ComfyUI Node

Switch

Flip between N inputs of any type with one widget

By Immac·Created 11 months ago·Updated 6 months ago· 0
Switch
  • input_0
  • input_1
  • input_2
  • input_3
  • input_4
  • input_5
  • input_6
  • input_7
  • input_8
  • input_9
  • input_10
  • input_11
  • input_12
  • input_13
  • input_14
  • input_15
  • input_16
  • input_17
  • input_18
  • input_19
  • value
num_inputs5
index0
one_indexedfalse

Switch is the A/B switch that grew a numeric keypad. You give it up to twenty inputs of any type, set an integer index, and it passes through whichever slot you pointed at. Two model loaders, three prompt variants, a handful of latent paths - wire them all in, flip one number, done. This is the classic "manual routing valve" pattern that every logic pack ends up shipping, and this one is clean and small.

The inputs that matter:

  • num_inputs - how many slots are visible (default 5, up to 20). Change it and the node adds or removes sockets live.
  • index - which slot to return. Zero-indexed by default: 0 is the first input. -1 always returns None.
  • one_indexed - flip to 1-based numbering if you think in "first, second, third." With it on, index 0 returns None.
  • input_0input_19 - the actual slots, all * type, so they accept anything.

Output is a single value socket carrying whatever the selected slot held.

Two details are worth knowing before you rely on it. First, all twenty slots are statically declared in the node's schema, and a small frontend extension (web/js/switch_node.js) shows or hides them to match num_inputs. If the JS doesn't load for some reason the node still works - you just see the full twenty. Second, the selection is pure data routing: whatever index you pick, the other inputs still get evaluated by ComfyUI because the switch can't know which one you'll want until run time. In plain terms, switching doesn't save you the compute of the unselected branches - it only decides which result goes downstream.

The one place people get burned is off-by-one confusion. Default is zero-indexed and index defaults to 0, so a fresh node returns input_0. The tooltip spells it out: -1 always returns None, and one_indexed shifts the numbering so 1 means the first slot and 0 means None. If a switch "returns nothing," check that you're not pointing at a slot you think of as "one" but the node reads as "two."

Installing it

Ships in ComfyUI-ImmacTools by Immac - MIT-licensed, personal-use, zero dependencies and no model files. Install via ComfyUI Manager by repo URL or:

cd ComfyUI/custom_nodes
git clone https://github.com/Immac/ComfyUI-ImmacTools

Restart ComfyUI. It's the one node in the pack with a real category (immac/logic) - search "Switch" or "Immac" in the node menu. Note the pack needs a recent ComfyUI (it uses the newer ComfyExtension API), and the slot-counting behavior needs the frontend JS to load, which it does automatically via the pack's web directory.

Common issues

Beyond the indexing gotchas above: if you're using this to pick between heavy branches - two different checkpoints, say - remember the losing branch still runs. If that's a problem, mute the unselected loader instead (bypass or a group muter), or keep only the active branch wired. And because the sockets are *, a wrong-type connection won't error here; it'll surface at the first typed node downstream.

Categoryimmac/logic

Inputs (23)

NameTypeDefaultDescription
num_inputsINT51–20Number of visible input slots.
indexINT0-1–19Index of the input to select. -1 always returns None.
one_indexedBOOLEANfalseWhen enabled, index 1 selects the first input slot. Index 0 will return None when this is on.
input_0opt*
input_1opt*
input_2opt*
input_3opt*
input_4opt*
input_5opt*
input_6opt*
input_7opt*
input_8opt*
input_9opt*
input_10opt*
input_11opt*
input_12opt*
input_13opt*
input_14opt*
input_15opt*
input_16opt*
input_17opt*
input_18opt*
input_19opt*

Outputs (1)

NameTypeDescription
value*