Nodes/ComfyUI 1hewNodes/Any Switch Bool
ComfyUI Node

Any Switch Bool

An if/else for the graph, with lazy evaluation that skips dead branches

By 1hew·Created about a year ago·Updated 8 days ago· 33
Any Switch Bool
  • on_true
  • on_false
  • output
booleantrue

Any Switch Bool (1hew_AnySwitchBool) is the closest ComfyUI gets to an if/else statement, and it's one of those nodes that quietly changes how you build graphs. A boolean decides which of two inputs - on_true or on_false - gets passed to the output. That's it. But the lazy evaluation is what makes it actually good.

Normally ComfyUI evaluates every node upstream of anything you run, whether you use the result or not. This node declares that it only needs one of its two branches, so ComfyUI skips the other entirely. That means you can hang an expensive branch - a second sampler, a heavy upscaler - off the switch, gate it with a boolean, and the dead branch never runs. It's a wiring-level way of doing what you'd otherwise solve with bypass or a group-mute, except it's data-driven: flip a boolean and the graph re-routes itself.

How it works

The mechanism is simple enough to read in one glance: bool(boolean) picks the key, the chosen branch's value is returned as the output. The wildcard (*) input and output types mean it carries anything - an image, a mask, a string, a conditioning - so you can switch on any type without conversion nodes. If you disconnect one branch, the switch still works with the other connected one; the lazy logic only requests the branch that's live.

Inputs and outputs

  • boolean - the switch, default true.
  • on_true (optional, any type) - what comes out when the boolean is true.
  • on_false (optional, any type) - what comes out when it's false.
  • output (any type) - the routed value.

Installing it

It's part of the 1hewNodes pack:

cd ComfyUI/custom_nodes
git clone https://github.com/1hew/ComfyUI-1hewNodes

or search "1hewNodes" in ComfyUI Manager, then restart. No dependencies beyond the pack's standard set.

The real uses

Pair it with the pack's Any Empty Bool and you get guard logic: "only route this branch if there's actually a mask here." Or with Int Number Compare: "run the hires pass only if the batch is bigger than four." It's also the clean way to A/B two different samplers or two LoRA stacks - flip one boolean instead of rewiring.

Two things to keep in mind. First, because of lazy evaluation, if a workflow loads and the unselected branch has an error in it (say, a missing model), you won't see the error - ComfyUI never executes it. That's a feature until it's a bug, and then it's confusing. Second, the switch routes whole values, not per-frame items; for per-batch routing you'd want a list-based approach. For everything else, this is the pack's best "if I had a conditional" answer.

Category1hewNodes/logic

Inputs (3)

NameTypeDefaultDescription
booleanBOOLEANtrue
on_trueopt*
on_falseopt*

Outputs (1)

NameTypeDescription
output*