ComfyUI Node

Swap

Swap

By antrobot1234·Created 3 years ago·Updated about a year ago· 28
Swap
  • val1
  • val2
  • valA
  • valB
doSwap

Swap takes two inputs of any type and a boolean, and either passes them straight through or crosses them over. Boolean off: input 1 goes to output A, input 2 to output B. Boolean on: they trade places - 1 to B, 2 to A. That's the entire node, and it's more useful than that description makes it sound.

Why you'd reach for it

It shines in pipe-heavy workflows. Say you've got two pipes - a base and a refiner, or a "day" and "night" version of a setup - and you want to flip which one drives the rest of the graph. Without Swap you're dragging wires around by hand every time. With it, you flip one boolean and the two branches trade routes. Because both inputs and both outputs are the wildcard * type, it works on literally anything: models, latents, images, pipes, conditioning. One node, any type, instant A/B.

It's worth being clear about how this differs from rgthree's switches, which are the other node people use for this kind of thing. A switch picks one of several inputs and drops the rest. Swap keeps both and just reorders them - nothing gets discarded. So reach for Swap when you want to reverse or reroute two live paths, and reach for a switch when you want to select one and mute the others.

How it works

There's no magic. It reads doSwap; if false it maps val1 to valA and val2 to valB, and if true it maps val1 to valB and val2 to valA. Both values pass through untouched - this is pure routing, not a transform.

The inputs and outputs

  • val1 / val2 - the two inputs, any type (*). They should be things you're happy to see come out of either output slot.
  • doSwap - the boolean. False = pass through, True = cross over.

Outputs are valA and valB, both *, carrying whichever input the boolean routed to them.

Installing it

ComfyUI Manager → search antrobots ComfyUI Nodepack, install, restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/antrobot1234/antrobots-comfyUI-nodepack

Pure graph plumbing - no models, no dependencies.

Common issues

The * type is the source of the only real gotcha. ComfyUI figures out a wildcard node's type from what you connect, and it can't reorder two things that aren't the same kind. In practice you want val1 and val2 to be the same type - two pipes, or two images - so that either can validly flow to either output. Feed it an IMAGE and a LATENT and the downstream connection gets ambiguous.

The other thing: don't overthink which output is which. If your swap seems "backwards," you've just got the boolean set the way you didn't expect - flip doSwap and it's fixed. There's no hidden state.

Wildcard-typed nodes like this one occasionally render awkwardly under ComfyUI's newer Nodes 2.0 frontend, which has been rough on custom node widgets across the ecosystem. If the node looks broken, try it on the legacy canvas before assuming the node itself is at fault.

Categoryantrobots-ComfyUI-nodepack/flow-control

Inputs (3)

NameTypeDefaultDescription
val1*
val2*
doSwapBOOLEAN

Outputs (2)

NameTypeDescription
valA*
valB*