Alternating Output
Swap between two images on a fixed schedule — image A every N rounds, image B in between
- input_a
- input_b
- image
- width
- height
- counter
You've got two reference images and you want to alternate between them on a schedule - image A on render 1, image B for the next few, A again, and so on. Alternating Output is that switch, and it's about as literal as a node gets: feed it two images, tell it which one shows first and how often the other one takes over, and it hands you back whichever image it's that image's turn to be.
The use case that actually sells it: a looped workflow where a reference image drives the generation via IPAdapter or img2img, and you want the style/pose/character to change every N frames. Or a head-to-head where the same pipeline gets rendered against two different references on alternating runs so you can compare them without rebuilding the graph.
How it works
It runs on a feedback counter, which is the one thing you must understand. The counter input is the round number. On round 0, it outputs whatever first_output says. After that it's dead simple: when counter % n == 0 it outputs input_a, otherwise input_b. So with n at 5 and first_output = input_a, you get A, B, B, B, B, A, B, B, B, B - A every fifth round, B filling the gaps.
first_output only changes what happens on round one. Set it to input_b and the first image is B, but the every-nth-A rhythm continues unchanged.
Honest note: the README's worked example (n=3, first_output=B → "BAABAABAAB") doesn't match the code as shipped. The code is the simple counter % n rule above, so trust the node's actual behavior, not the docs' sequence - the docs rot, the source doesn't.
The inputs and outputs
Required inputs: input_a and input_b (both IMAGE, force-input), n (1–10000, the interval between A's), first_output (pick input_a or input_b), and counter (default 0). Outputs: image (the selected image), width and height (of the selected image - handy if a downstream node needs the dims), and counter, which is the round number incremented by one.
Here's the catch that trips everyone: the node only alternates if you wire the counter output back into the counter input. If you leave it at the default 0, every run is "round 0" and it outputs first_output forever. The feedback loop is the node. It also means the alternation only advances when ComfyUI actually re-executes it - connect it to something that keeps its hash changing (any changing input in the chain) or it'll sit on round one.
Installing it
Part of the ComfyUI-Counternodes pack. Install via ComfyUI Manager (search ComfyUI-Counternodes), or:
cd ComfyUI/custom_nodes
git clone https://github.com/GHOSTLXH/ComfyUI-Counternodes
Then restart ComfyUI. Pure Python, no models, no extra deps.
Gotchas
The feedback loop is the big one - forget it and you're stuck on one image. Also, the two inputs should be the same resolution; the node doesn't resize, so a mismatch just flows downstream as inconsistent sizes. And keep in mind only one image comes out per run, so this is a selector, not a merger - wire its output into a conditioning or reference input and each run generates with whichever image is "up."
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| input_a | IMAGE | — | |
| input_b | IMAGE | — | |
| n | INT | 51–10000 | — |
| first_output | COMBO | input_a | 2 options: input_a, input_b |
| counter | INT | 00–10000 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| width | INT | — |
| height | INT | — |
| counter | INT | — |