ComfyUI Node

If Condition

The if/else that only runs one branch

By Duanyll·Created 11 months ago·Updated 4 months ago· 2
If Condition
  • true_value
  • false_value
  • *
condition

If Condition is a fork in the road for your data. Give it a boolean, and it hands back true_value when the condition is True and false_value otherwise. Sounds trivially simple - and the simplicity hides the useful part, which is that only the chosen branch actually runs. In vanilla ComfyUI, both branches of an if/else get evaluated whether you use them or not. This node refuses to do that, and that's the whole reason it exists.

The inputs

  • condition - a BOOLEAN, from a comparison, a Logic node, a model check, whatever.
  • true_value - the value returned when condition is True.
  • false_value - the value returned when condition is False.
  • output - whichever branch won, same type as the inputs (they should match, but nothing enforces it).

The node's own description says it plainly: "Returns true_value if condition is True, else returns false_value. Supports lazy evaluation." Lazy is the feature, not the bug.

Why lazy evaluation matters here

The pack wires both true_value and false_value as lazy inputs - ComfyUI only computes the one that's needed. That matters far more than it sounds. The classic ComfyUI problem: you want "if upscaling is enabled, run the upscaler; else pass the image through." With a naive if/else, the expensive upscaler runs anyway, then its result is thrown away. With this node, the losing branch never executes - saving GPU time, and more importantly, never running code that might error (like an upscaler fed a latent it can't handle). This is the same short-circuit philosophy as the pack's Logical AND/OR nodes.

The corollary: don't wire anything with side effects into the losing branch and expect it to run. Only the selected branch executes - that's the deal.

How it works

The check_lazy_status hook looks at the condition and requests only the matching input from the executor. If condition is True, only true_value is requested; otherwise only false_value. The result is a single pass-through of the winning value.

Where people get burned

  • Mismatched branch types. Nothing stops you from returning an image on one side and a number on the other. ComfyUI will accept it, then the downstream node will have opinions. Keep both branches the same type.
  • Expecting both branches to run. They don't. If you're using If Condition to log both paths, you need the side-effect helpers instead.
  • Feeding it a non-boolean. The condition socket is typed BOOLEAN; if your source is a number, convert it first.

Installing it

Part of Duanyll/comfyui_functional (logic category). ComfyUI Manager: search "Duanyll/comfyui_functional", or:

cd ComfyUI/custom_nodes
git clone https://github.com/Duanyll/comfyui_functional
# restart ComfyUI

No models, no pip deps. This is the pack's most portable node - it doesn't need LISTs or closures, so you can drop it into almost any workflow to make a conditional branch actually lazy.

Categoryduanyll/functional/logic

Inputs (3)

NameTypeDefaultDescription
conditionBOOLEAN
true_value*
false_value*

Outputs (1)

NameTypeDescription
**