Any Switch
Pick whichever branch you actually wired up
- *
If you have ever built a workflow with an optional reference image - sometimes you have one, sometimes you don't - you already know the pain. You bypass the loader, and now a required input is missing. You keep two copies of the workflow and forget which is which. Any Switch is the small node that ends that.
What it is
A fallback switch. Not an A/B switch with a selector - those pass whichever input you point them at, and a graph where you flip the selector yourself. This one has no selector at all: it walks its inputs in order and hands back the first one that is connected and not None. Nothing connected, and you get None.
That distinction is the whole design, and it is the same shape rgthree's Any Switch established: "chooses the first input that is not null/empty." The fallback shape is what lets you build a graph with several optional upstream branches feeding one downstream consumer. Whichever branch is live wins, and you never touch a switch.
How it works
The inputs are wildcard slots. On the canvas they are numbered (any_01, any_02, …), the node keeps one empty slot waiting at the end, and the socket takes the type and colour of whatever you plug in - so the canvas shows and type-checks the real thing, not an anonymous * on every slot. Empty slots in the middle are removed and the rest renumbered, so slot order is always what you see, top to bottom.
On the Python side the class declares a flexible optional input map and a VALIDATE_INPUTS that accepts anything, which is how ComfyUI's type system gets out of the way; then it returns the first non-None value it finds, walking the slots in numeric order. One output, named *, carrying whatever came through.
Typical wiring, and the order matters:
LoadImage (optional reference) -> any_01
EmptyImage / LoadImage (fallback) -> any_02
Reverse those and the fallback always wins, because nothing downstream knows your intent - it just takes the first slot with something in it.
Installing it
Any Switch is part of ComfyUI-BCNodes, a utility pack. Easiest route is ComfyUI Manager: search ComfyUI-BCNodes, install, restart. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/0xBeycan/ComfyUI-BCNodes
pip install -r ComfyUI-BCNodes/requirements.txt
Restart ComfyUI and reload the browser tab - a chunk of this pack is frontend JavaScript, and the slot-growing behaviour lives there. Then search BCNodes in the node library; the pack's logic nodes sit under BCNodes/logic.
Worth knowing before you write any issue: if you still have a folder called ComfyUI-AutoBypass from the pack's previous life, delete it. It registers one of the same nodes under different names, and you'll end up with two.
Where people get burned
Empty is not None. A node that runs and outputs an all-black image, or an all-zero mask, has succeeded - it emitted a tensor, and the switch will happily take it. If your "optional" branch is a mask that came back empty, Any Switch can't tell, and neither will you until you look at the image. That's what Is Mask Empty and Logic Boolean are for: turn the emptiness into a real boolean first, and gate the branch with that.
A bypassed node upstream leaves the slot unconnected, which reads as None - usually what you want. But it also means a typo-style mistake (loader bypassed on purpose last week, forgotten) looks exactly like a deliberately absent branch.
None into a required input fails at run time, not at validation. The link exists, so ComfyUI's pre-flight check passes, and then the receiving node chokes on None mid-queue. If a workflow dies with a confusing error on a node you thought was fully wired, check what fed it.
Is it worth installing the pack for?
Not on its own - this is one small node. But it pairs with the rest of the pack's logic kit, and if you're on the new frontend and something in rgthree has gone sideways for you, having a second implementation of a fallback switch is cheap insurance.
Inputs (0)
No inputs
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |