Any Switch (Swwan)
Use A if you've got it, else B
- 优先输入
- 备用输入
- 是否启用优先
- 输出结果
Any Switch answers a question ComfyUI asks surprisingly often: which of these two things should flow through? Unlike a toggle switch, it has no button. It looks at its two inputs and picks the first one that actually has data. Priority input connected and non-null? That's what you get. Priority is empty? Fall back to the backup input. It's null-coalescing - the ?? operator turned into a node.
If you've used rgthree's Any Switch, this is the same family. It comes from the ComfyUI_Swwan pack, a Chinese author's grab-bag that re-implements a bunch of popular utilities. As with the pack's Any Boolean Switch, the labels are Chinese: 优先输入 (priority input), 备用输入 (backup input), and the outputs 是否启用优先 (whether priority is active) and 输出结果 (output result). Worth knowing before you stare at it wondering if your install is broken.
How it works
Two optional inputs, both Any-typed so they accept anything:
优先输入- checked first.备用输入- used only if priority isNone.
The logic is dead simple: is_active = 优先输入 is not None, then output the priority if active, otherwise the backup. It also emits 是否启用优先, a boolean telling you which branch won - handy if you want downstream nodes to behave differently depending on the source.
Because both inputs are optional and the node validates any input type, you can leave one side unwired entirely. A node with only the backup connected behaves as a pass-through; only the priority connected and it behaves as a pass-through that's always "active." It's the flexible "give me whichever exists" junction for a graph where data might come from one of several places.
When you'd use it
The typical pattern is a fallback chain. Say a workflow can take either an image from a folder-loading node or a manually-connected default - route both into Any Switch and the non-empty one wins. Or you have a lazy node that may produce nothing, and you want a placeholder image in its place. It's also the glue for optional inputs that change per run without you editing the graph each time.
Installing it
It ships in ComfyUI_Swwan:
cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
pip install -r ComfyUI_Swwan/requirements.txt
Or install the pack via ComfyUI Manager, search "ComfyUI_Swwan".
Where people get burned
The catch is the same as any null-checking switch: it only switches on None. An empty-but-valid value (a blank string, a zero-sized tensor, a latent with a zero batch) is not None, so it counts as "present" and the priority branch wins even when it contains nothing useful. If your upstream can produce empty-but-real data, make sure it produces actual None before you rely on the fallback. And since there's no widget, there's nothing to toggle - if you want a manual A/B switch, use the pack's Any Boolean Switch instead.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| 优先输入opt | * | — | |
| 备用输入opt | * | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 是否启用优先 | BOOLEAN | — |
| 输出结果 | * | — |