if/else
Pick a path at runtime — and only compute the branch you actually take
- if_true
- if_false
- result
ComfyUI is a graph, and a graph's big weakness is that every node connected to the sampler runs every time. if/else is how you break out of that. Give it a boolean, it hands you one value or the other - and in this particular implementation it's lazy, so the branch you don't take never gets computed at all. That last part is why this node beats wiring up a manual switch for a lot of workflows.
It ships in Basic data handling, StableLlama's zero-dependency utility pack. StableLlama is a real community regular - they post model-evaluation writeups on r/StableDiffusion and publish training datasets - and this pack is the "every Python builtin, but as a node" collection. If/else is one of the flagship nodes because conditional routing is something core ComfyUI genuinely lacks.
How it works
The mechanism is a one-liner: if_true if condition else if_false. The interesting part is check_lazy_status. The two value inputs are marked lazy, which means ComfyUI asks the node which inputs it actually needs before scheduling them. If your condition is True, the node reports it only needs if_true, and the whole upstream chain feeding if_false is skipped - no wasted generations, no wasted VRAM. Flip the condition and the other side gets skipped instead.
In practice that means you can branch on expensive things. Condition on a face-detection boolean and route to a detailer on one side and a plain sampler on the other; whichever branch you take, the other simply doesn't run. That's a genuinely nice property that a lot of if/else-style nodes don't bother implementing.
The inputs that matter
condition(BOOLEAN) - the switch. Comes from any comparison node, the pack's boolean logic, or a primitive.if_true(*) - returned when condition is true. ANY type, so it can be a model, a prompt, a seed - anything.if_false(*) - returned when condition is false. Same ANY flexibility.
Output: result (*), whichever branch won.
Because both value inputs are ANY, you can wire a checkpoint into if_true and a different checkpoint into if_false and route the winner straight into the sampler. Same trick works for prompts, LoRA stacks, you name it.
Installing it
Install the pack from ComfyUI Manager (search "Basic data handling"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI. No dependencies, no model downloads - the whole pack is pure Python.
Common issues
- "Both sides still ran." Check whether you actually wired both value inputs. Lazy evaluation only skips a side when the node can avoid fetching it - if you connected both branches it still only returns one, but if the skipped input is fed by a non-lazy node it may execute anyway. For genuinely expensive branches, make sure the condition is computed before anything you're trying to save.
- "I want three or more branches." This node is binary. The same pack ships
if/elif/elseandswitch/casein the Control Flow category - reach for those when if/else starts nesting into a mess. - "Output looks like the wrong type." The output is ANY, so downstream nodes may complain until the value actually flows. Feed the result into the pack's cast nodes (
to STRING,to INT) if the next node is picky.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | BOOLEAN | — | |
| if_true | * | — | |
| if_false | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | * | — |