IF
The conditional router that turns your workflow into actual logic
- when_true
- when_false
- result
This is the node people actually search the pack for. LogicIF is ComfyUI's conditional router: give it a boolean and two candidate values, and it passes through one or the other depending on the flag. It's the difference between a workflow that's a straight line and one that makes decisions - and once you've routed your first output with it, you'll wonder how you lived without branches.
Real-world pattern: an LLM (via ollama or similar) or a vision node says "YES" or "NO" about an image, a compare node turns that into a boolean, and the IF routes the image to a "keep" save node or a "reject" save node. That's literally what someone on r/comfyui was building when they hit this exact node. The same shape covers "if the model is a flux checkpoint, use this workflow branch, else that one," or "if denoise is above 0.6, upscale, else don't."
How it works
Three inputs, one decision. if_condition is the boolean that decides. when_true is what comes out the result output when the condition is true; when_false is what comes out when it's false. Both candidates are typed as any-type inputs, which is the whole point - this node routes anything: images, conditioning, numbers, latents, models. It doesn't care what you pass through it.
The one thing to watch: when_false is optional, and if you leave it unconnected and the condition evaluates false, the node returns a Python None. That value then flows downstream and produces the classic Expected torch.Tensor, got <class 'NoneType'> error - the exact failure from the routing workflow mentioned above. So: if your branch can ever take the false path, wire when_false to something, even if it's a dummy. If you truly only want a passthrough when true, that's a different (simpler) pattern and this node isn't it.
The inputs that matter
if_condition(boolean) - the decision input. This is the one people forget to wire; nothing routes if it's dangling.when_true(any) - passed through when the condition is true.when_false(any, optional) - passed through when false; leaving it unset is the #1 gotcha.
Output is result, any type - wire it into whatever downstream node expects the routed value.
Install
Part of the ComfyUI-LogicMath pack. Install via ComfyUI Manager (search "ComfyUI-LogicMath", Install, restart) or:
cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-LogicMath
No dependencies, no downloads. It targets ComfyUI's newer extension API, so update ComfyUI if the nodes don't appear.
Common issues
Expected torch.Tensor, got NoneTypedownstream -when_falseis unconnected and the false branch fired. Give it a value.- Nothing happens no matter what -
if_conditionisn't wired. Check the actual decision point, not the outputs. - The node is opinionated about types - because both inputs are any-type, you can route a tensor one way and a number the other in the same node, which is powerful but easy to misuse. Keep the two branches the same type unless you know what you're doing.
The one design note: IF passes through whatever you give it - it doesn't transform anything. Think of it as a rail switch, not a filter. Wire it right and you've just made your graph conditional, which is a bigger upgrade than it sounds.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| if_condition | BOOLEAN | — | |
| when_true | * | — | |
| when_falseopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | * | — |