Nodes/ComfyUI_Swwan/Any Boolean Switch (Swwan)
ComfyUI Node

Any Boolean Switch (Swwan)

A switch that skips work it doesn't need

By aining2022·Created 9 months ago·Updated 11 days ago· 33
Any Boolean Switch (Swwan)
  • 输入
  • 输出结果
开关true

Most switch nodes in ComfyUI are routing widgets: they pick between two inputs and pass one through. Any Boolean Switch is that, but with a genuinely useful trick - when it's off, the thing feeding it never runs. Flip the switch and an entire expensive upstream branch (a second sampler, a whole ControlNet stack, an upscale) simply doesn't execute. That's the difference between "skip the output" and "skip the work," and it's why this little node shows up in big workflows that get toggled a lot.

It lives in the "Swwan/utils" corner of the ComfyUI_Swwan pack, alongside the pack's other Any-type utilities. One heads-up before we go further: the input and output names are Chinese. On the node you'll see 输入 (input), 开关 (switch), and 输出结果 (output result). Don't let it throw you - the behavior is exactly what the English display name promises.

How it works

Two inputs, one output:

  • 输入 - any data type at all (it's an Any socket, so it accepts IMAGE, LATENT, STRING, whatever).
  • 开关 - a boolean toggle, on by default.

When the switch is on, whatever you fed in comes straight back out of 输出结果. When it's off, you get None - and here's the clever part: the node declares itself lazy, telling ComfyUI not to evaluate the input unless the switch is on. Since ComfyUI only runs nodes whose outputs are actually needed, turning the switch off prunes the entire upstream branch from the execution graph. This is the same lazy-evaluation trick rgthree's Any Switch popularized, just driven by an explicit toggle instead of a null check.

When you'd use it

The classic case is A/B testing inside one saved workflow: route one latent into "keep" or "bypass" without deleting nodes. Another is a quality toggle - a "draft vs. final" switch where the final path runs a heavier upscaler and the draft path skips it entirely. Because the off-branch never computes, you don't pay even the setup cost of loading whatever models it needs.

Installing it

It ships in ComfyUI_Swwan. Install via ComfyUI Manager (search "ComfyUI_Swwan") or:

cd ComfyUI/custom_nodes
git clone https://github.com/aining2022/ComfyUI_Swwan
pip install -r ComfyUI_Swwan/requirements.txt

The pack bundles a bunch of migrated utility nodes, and this one is in the same lineage as rgthree's switches - if you already run rgthree-comfy, you'll find a near-equivalent there.

Where people get burned

Because the off-state returns None, anything downstream that isn't built to accept a null can error when you switch it off. Wire the switch's output into a node that handles None gracefully (or a reroute), and don't expect the off-state to produce a useful image - that's not what it's for. Also remember the toggle widget sets the state per-workflow-save, so export a workflow with the switch in the position you intend to share.

CategorySwwan/utils

Inputs (2)

NameTypeDefaultDescription
输入*
开关BOOLEANtrue

Outputs (1)

NameTypeDescription
输出结果*