Nodes/ComfyUI_Mira/Function Swap
ComfyUI Node

Function Swap

Flip two wires with one boolean

By mirabarukaso·Created 2 years ago·Updated 9 days ago· 206
Function Swap
  • func1
  • func2
  • A
  • B
triggerfalse

Function Swap takes two inputs and two outputs and lets a single boolean decide whether they pass straight through or cross over. Toggle off, A gets the first input and B gets the second. Toggle on, they swap - A gets the second, B gets the first. Because the inputs are typed as "any" (*), it works on whatever you throw at it: masks, images, conditioning, latents, numbers. It's a crossover switch.

The reason this exists is regional / two-subject work, which is exactly what mirabarukaso built ComfyUI_Mira around. Say you've got two masks and two prompts for a left character and a right character. Sometimes you want to reverse who's where without re-drawing masks or re-typing prompts - one toggle on Function Swap flips both assignments at once. Regional prompting is one of the most common reasons people put up with ComfyUI's graph in the first place, and small routing nodes like this are what make experimenting with it bearable. Function Swap sits in the pack's Logic family with the rest of the switching glue.

How it works

func1 is the first input, func2 the optional second, and trigger is the boolean that controls the crossover. With trigger False, outputs pass through in order (A=func1, B=func2). With trigger True, they swap (A=func2, B=func1). A recent update made func2 optional with a sensible fallback: if func2 isn't connected (or is bypassed), both outputs return func1, so a half-wired node degrades gracefully instead of erroring.

The inputs and outputs that matter

  • func1 - the first value (any type).
  • trigger - the boolean that decides swap or pass-through (default False).
  • func2 (optional) - the second value; if absent, both outputs become func1.
  • A / B (outputs) - the two values, in normal or swapped order per trigger.

Drive trigger from any boolean source - a manual toggle, the Not node, an even/odd check - and you've got a controllable crossover.

Installing it

ComfyUI Manager: search ComfyUI_Mira, install, restart. Or clone:

cd ComfyUI/custom_nodes && git clone https://github.com/mirabarukaso/ComfyUI_Mira.git

then restart. If it errors on load, run pip install -r requirements.txt in the ComfyUI_Mira folder. It's under Mira/Logic.

Common issues

  • Both outputs are the same when func2 is missing. That's the documented fallback, not a bug - connect func2 if you actually want a swap. If your A and B are identical, check that second input.
  • Any-type means you own the type safety. Since it passes *, nothing stops you feeding it two mismatched types; the downstream node is where a mismatch will blow up. Keep A and B feeding into sockets that accept whatever you routed.
  • Swap vs. select. Function Swap always outputs both wires (just reordered). If you instead want to pick one of two branches and drop the other, that's Function Select Auto, not this.
CategoryMira/Logic

Inputs (3)

NameTypeDefaultDescription
func1*
triggerBOOLEANfalse
func2opt*

Outputs (2)

NameTypeDescription
A*
B*