Nodes/comfyui-misc/Any Switch (misc)
ComfyUI Node

Any Switch (misc)

Pick the first input that isn't empty, and know which one won

By wraith-executioner-year-2·Created 3 months ago·Updated 2 months ago· 1
Any Switch (misc)
  • any_01
  • *
  • index
select_index-1

If you've ever built a workflow with two or three optional branches and one consumer at the end, you know the drill: every branch has to produce something, or the graph errors out. Any Switch (misc) is the valve that fixes that. It's a first-non-null switch - wire up as many any_* inputs as you like, and it hands the first one that actually has content through to its single * output. No selector to touch, nothing to configure, and because it's a wildcard type it doesn't care whether it's routing an IMAGE, a LATENT, a string, or a model.

It's essentially rgthree's Any Switch with one useful addition: an index output that tells you which branch won. If you've used rgthree's version you'll recognize the whole shape instantly; this one is built on the same fallback logic and keeps that "first non-empty wins" behavior.

The two inputs that matter. select_index is the only widget, defaulting to -1. Leave it there and the node scans any_01, any_02, … in order and picks the first non-empty slot. Set it to 0 or higher and it forces the selection to any_{index+1} - so 0 grabs any_01, 3 grabs any_04. If the forced slot happens to be empty, it falls back to the first non-empty one rather than erroring, which is a nice touch. The any_* inputs themselves are dynamic optional slots; they appear as you connect things, so you never deal with fixed counts.

What counts as "empty"? Just None, plus a special case: if you feed it an rgthree-style CONTEXT dict whose model/clip fields are all empty, it treats that as empty too. So you can feed a context-bus branch that technically exists but carries nothing, and it gets skipped instead of winning.

The outputs. * is the chosen value, and index is its 0-based number (INT). Wire index somewhere if the downstream node needs to know which branch fired - like labeling which sampler or which model produced the result. That's the one thing this node adds over the pack it's modeled on.

Install. Same as the rest of the pack, from ComfyUI/custom_nodes:

git clone https://github.com/wraith-executioner-year-2/comfyui-misc/

Then restart ComfyUI. It lives in the misc category. There are no model downloads and no Python dependencies beyond what ComfyUI already ships - this is pure routing logic plus a bit of frontend JS.

Where people get burned: the node is genuinely type-blind (*), which is the point, but it also means the graph won't warn you if you swap an IMAGE branch and a LATENT branch into the same switch and only one path happens to be wired correctly at runtime. Type-erasing convenience is the same trade-off the "Anything Anywhere" backlash was about - it's fine until you're debugging why a node silently got the wrong shape. Also note this is a tiny, lightly-visited pack; the dynamic-slot frontend is real and maintained (the changelog shows active fixes through mid-2026), but don't expect a big community behind it if you hit a bug.

Categorymisc

Inputs (2)

NameTypeDefaultDescription
select_indexINT-1-1–4096
any_01opt*

Outputs (2)

NameTypeDescription
**
indexINT