Nodes/ComfyUI-Counternodes/Alternating Output B
ComfyUI Node

Alternating Output B

The other two-image switcher — same idea, different rhythm

By GHOSTLXH·Created 2 years ago·Updated 2 years ago· 11
Alternating Output B
  • input_a
  • input_b
  • image
  • width
  • height
  • counter
n3
first_outputinput_a
counter0

Alternating Output B is the sibling node to the pack's plain Alternating Output, and it's the one the author labels "常用" (commonly used). The job is identical - pick between two images on a schedule - but the rhythm is different, which is the whole point of having both. Where the A version is "image A every N rounds, B filling the gaps," the B version lets the first image set the phase of every cycle instead of just round one.

It's for the same looping-reference workflows: IPAdapter reference swaps, img2img source changes, A/B comparison runs. If you've already wrapped your head around Alternating Output, you're 90% of the way here; the only real question is which cadence you actually want.

How it works

Same feedback-counter setup as the A version: you feed the round number in via counter and wire its counter output back in to keep the loop alive. On round 0 it outputs first_output. From then on it computes (counter - 1) % n; if that's 0 it outputs the same image as first_output, otherwise it outputs the other one.

Trace it for first_output = input_a, n = 3: round 0 → A, round 1 → A, rounds 2–3 → B, round 4 → A, rounds 5–6 → B, and so on: A A B B A B B A B B. For the README's example (first = B, n = 3) the actual code produces B B A A B A A - note that's not the BBBABBBABB the README claims, so trust the node over the doc's example sequence, same as with the A version. The practical difference between A and B: A locks one image to "every n-th round," while B places first_output at the start of every cycle, which shifts which rounds the other image gets. Pick whichever phase your loop needs.

Inputs and outputs

Required: input_a, input_b (both IMAGE), n (here with a min of 2 - one round of the first image isn't a cycle), first_output (choose input_a or input_b), and counter (default 0). Outputs: image, width, height (of the chosen image), and the incremented counter you feed back in.

Same critical detail as the A version: without the counter output → counter input loop, every run is round 0 and it's stuck on first_output. The node is a selector, not a merger - one image out per run - and both inputs should match resolution.

Installing it

It's in the ComfyUI-Counternodes pack, so one install gets all six nodes. ComfyUI Manager: search ComfyUI-Counternodes. Or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/GHOSTLXH/ComfyUI-Counternodes

Restart ComfyUI. No models, no extra dependencies - just Python and torch, which ComfyUI already ships.

Gotchas

Same three as its sibling: forget the counter feedback loop and it never alternates; feed it mismatched resolutions and the inconsistency flows downstream; and if ComfyUI caches the node because nothing in its inputs changed, the alternation stalls. Keep something in the chain changing each run and you're fine. If you're choosing between A and B, don't overthink it - build the loop with one, and if the swap lands on the wrong rounds, swap to the other. It's a phase adjustment, not a rewrite.

CategoryUtils

Inputs (5)

NameTypeDefaultDescription
input_aIMAGE
input_bIMAGE
nINT32–10000
first_outputCOMBOinput_a2 options: input_a, input_b
counterINT00–10000

Outputs (4)

NameTypeDescription
imageIMAGE
widthINT
heightINT
counterINT