Iter_ImageSwitch
Step through a stack of images with Iter_ImageSwitch
- IMAGE
Every img2img user knows the drill: load reference image one, queue, swap in reference image two, queue, swap back. Iter_ImageSwitch automates that. It's an image switcher from the ComfyUI-IterSwitch pack - you wire a stack of IMAGE inputs into it, pick one by index, and it hands that image to whatever's downstream. If you've ever wanted to run the same workflow against several source images in a single pass, this is the node.
What it does
Connect up to 64 IMAGE inputs (from loaders, VAE decodes, or anywhere else images come from) and the node outputs one of them, selected by output_index. Drive that index from a counter node and one queue run walks through every source image: img2img variants, inpaint targets, reference images for a consistency pass - anything that consumes a plain image.
One thing worth noticing: this node's use_last_input defaults to off, unlike the rest of the pack. The author's own default here is "give me exactly the slot I pointed at," not "save me from myself." That's a deliberate design statement, and it means you should treat the fallback as something you turn on when you want resilience, not as assumed behavior.
How it works
Three widgets plus dynamically generated image_0, image_1, … sockets. input_count is wired to a web extension: raise it and new sockets appear; lower it and extras are trimmed from the end, leaving existing connections alone.
At run time the node computes target = output_index % input_count - an out-of-range index wraps around rather than erroring - and returns the image at that slot. With use_last_input on it walks backward from your target toward image_0 to return the nearest connected image instead; with it off, an unconnected target slot returns None.
Wiring it up
input_count- how manyimage_Nsockets exist; set before wiring.output_index- which image passes through. Wire a counter here to iterate.use_last_input- defaults off; turn on for backward-fallback to the nearest connected lower slot.
The IMAGE output feeds anything that takes an image - VAEEncode for img2img, VAEEncodeForInpaint with a mask, upscale nodes, IP-Adapter's reference input. The classic pattern is a stack of reference images feeding a fixed encode-and-sample chain, indexed per queue item.
Installing the pack
ComfyUI-IterSwitch has no extra Python dependencies - no requirements.txt, no model files. The install is one clone:
cd ComfyUI/custom_nodes
git clone https://github.com/younger15/ComfyUI-IterSwitch.git
Restart ComfyUI afterward so the frontend extension loads. Or via ComfyUI Manager: search "ComfyUI-IterSwitch," falling back to install-by-Git-URL if the registry doesn't list it - it's a small pack and may not be indexed yet.
Common issues
Noneout when you point at an unconnected slot. With the default fallback-off behavior, that's exactly what you get. If it's not intentional, flipuse_last_inputon and keep a wired image at a low index.- Sockets don't appear. The dynamic inputs are JavaScript; restart the backend and refresh the page (or fully restart ComfyUI) or the sockets never materialize.
- Silent wrap.
output_indexpast the count wraps via modulo. Handy for looping, easy to trip over if you're counting by hand.
Reality check: the pack has no community footprint yet - none of these nodes turn up in search-console data, so there's no crowd-sourced war stories to report. The code is small and readable if you want to verify the fallback behavior before trusting it; and if something's actually broken, the repo's issue tracker is where it belongs.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| output_index | INT | 00–18446744073709550000 | — |
| input_count | INT | 21–64 | — |
| use_last_input | BOOLEAN | false | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |