ComfyUI Node

IF

The ternary operator your workflows keep needing

By silveroxides·Created 2 months ago·Updated about 7 hours ago· 24
IF
  • when_true
  • when_false
  • result
if_condition

UC_LogicIF is the ternary operator of ComfyUI: pick a boolean condition, and it returns one value when true and another when false. if_condition true → hand back when_true; false → hand back when_false. And crucially, the values can be any type - not just booleans. Images, strings, conditioning, numbers, models. That's what makes it the most useful node in the logic family, because it's how you route real data, not just true/false flags, down different paths.

You'll reach for it the moment your workflow has an either/or that isn't just "run or don't run". Two samplers, pick by a toggle. Two LoRA weights, pick by model. Two prompts, pick by a seed check. Two upscalers, pick by GPU memory. The IF is the switch that makes the choice.

How it works

Three inputs: if_condition (boolean), when_true (any type), and the optional when_false (any type). One output: result, which is whatever you passed through. Because the types are wildcards (*), the output adopts the type of whichever branch is chosen - wire images through and you get an image out, wire a string through and you get a string.

One thing to know about the optional when_false: if you leave it disconnected, a false condition hands back None (the tooltip and source both treat it as optional). So if your downstream expects a real value in both branches, connect when_false explicitly - that's the single most common stumble.

The pattern that matters

IF is the branch mechanism that makes AND/OR (also in this pack) worth having. The logic gates compute whether; the IF computes what. UC_LogicAND says "all conditions met", and the IF then routes the actual payload - "so use the high-res sampler and the slow steps." It's the difference between a workflow that decides and a workflow that only confirms. If you're building anything stateful or adaptive, IF plus the pack's logic gates is the spine.

Install

Part of silveroxides/ComfyUI-UtilsCollection's logic family, which replaces the equivalent ComfyUI-LogicMath nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/silveroxides/ComfyUI-UtilsCollection

Restart (or ComfyUI Manager → search "ComfyUI-UtilsCollection"). Deps: opencv-python, typing-extensions. Remove the standalone LogicMath pack before accepting ComfyUI's replacement prompt to avoid duplicate node IDs.

The honest warning is the type one: because the output is a wildcard, ComfyUI can't always statically verify that what you feed in matches what the downstream expects. If your graph errors with a type mismatch after an IF, check that both branches actually hold the same kind of value. Feed it matching types and it's one of the most quietly load-bearing nodes in the pack.

Categoryutils/logic

Inputs (3)

NameTypeDefaultDescription
if_conditionBOOLEAN
when_true*
when_falseopt*

Outputs (1)

NameTypeDescription
result*