Nodes/ComfyUI-BooleanExpression/Conditional Branch
ComfyUI Node

Conditional Branch

ComfyUI's if/then, minus the surprises (mostly)

By marco-zanella·Created about a year ago·Updated about a year ago· 0
Conditional Branch
  • if_true
  • if_false
  • result
conditiontrue

Conditional Branch is the node that finally lets a ComfyUI workflow make a decision. Feed it a boolean, give it two values, and it hands back whichever one the condition picked. That sounds trivial until you've wired up your tenth workflow that needs to start from an empty latent or from an uploaded image, or swap a prompt based on aspect ratio, or pick a denoise value. Without something like this you're either forking the graph and muting half of it by hand, or you're rebuilding the workflow per variant.

It's the flagship of marco-zanella's ComfyUI-BooleanExpression pack, and the node the two example workflows in the README are built around. One of them is basically the exact use case above: a boolean toggle decides whether generation starts from an empty latent or from a VAE-encoded image, and a second Conditional Branch sets the right denoise factor. That's the pattern to steal.

What it actually does

The inputs are exactly what the name advertises: condition (a BOOLEAN, default true), if_true and if_false (both typed *, meaning any type), and one output, result. If the condition is true you get if_true out; otherwise if_false. Because the value slots accept anything, you can branch latents, conditioning, strings, numbers, even whole model references - whatever flows through the graph.

Here's the honest part you need to internalize: this is a value selector, not a control-flow fork. ComfyUI runs every node whose output is an input to another node, so both the if_true chain and the if_false chain get computed before this node runs; it just decides which result travels onward. If your two branches are a couple of text boxes, that costs you nothing. If a branch is a whole KSampler chain, the unselected branch still burns GPU time. This is the exact confusion people hit in r/comfyui threads about "conditional" nodes - a conditional branch won't disable the branch it didn't pick. If you genuinely want dead branches that don't execute, you need a mute/bypass-style switch (rgthree's stuff and a few others do this). For cheap values, which is what this node is for, it doesn't matter.

Wiring it in

The usual shape: an arithmetic comparison from the same pack (say, Greater than) compares two numbers and feeds condition; the two if_* inputs come from whatever you're choosing between; result feeds straight into the node that consumes it - a latent, a CLIPTextEncode prompt, a KSampler's denoise, whatever. The author even overrides IS_CHANGED so the node re-evaluates properly when values shift between runs, which is a nice touch that some bigger packs forget.

Installing it

No models, no dependencies, no API keys - this is pure Python, and the pack's requirements.txt is empty. Install via ComfyUI Manager (search ComfyUI-BooleanExpression), or the manual route:

cd ComfyUI/custom_nodes
git clone https://github.com/marco-zanella/ComfyUI-BooleanExpression.git

Then restart ComfyUI. The node lives under Boolean Expressions → Conditional Branch (the pack categories everything under "Boolean Expressions", so the search menu can get crowded - type "Conditional" to find it).

Common gotchas

  • Both branches execute. Already covered, but it's the #1 misunderstanding, so here it is again: unselected inputs still get computed upstream.
  • Wire real booleans into condition. A comparison node or a True/False constant from this pack gives you a proper BOOLEAN; don't try to improvise with a random INT and hope it coerces the way you want.
  • The * type cuts both ways. ComfyUI won't complain if you branch two different types - it'll happily pass either through. That's a feature for quick experiments, and a footgun in a workflow you plan to share. Keep the two branches the same type if you can.

If nodes don't show up after install, it's almost always the folder: restart ComfyUI, and if they're still missing, check you cloned into custom_nodes and not somewhere else. The pack is small, unopinionated, and does one thing - worth keeping on the shelf for any workflow that needs to think.

CategoryBoolean Expressions

Inputs (3)

NameTypeDefaultDescription
conditionBOOLEANtrueThe boolean condition.
if_true*Value to return if condition is met.
if_false*Value to return if condition is not met.

Outputs (1)

NameTypeDescription
result*