If Branch Router
The If Branch Router is ComfyUI's closest thing to a switch statement
- condition
- passthrough
- if_1
- if_2
- if_3
- if_4
- if_5
- if_6
- if_7
- if_8
- if_9
- if_10
- if_11
- if_12
- if_13
- if_14
- if_15
- if_16
- if_17
- if_18
- if_19
- if_20
- if_21
- if_22
- if_23
- if_24
- if_25
- if_26
- if_27
- if_28
- if_29
- if_30
- if_31
- if_32
- otherwise
ComfyUI is a graph, but "make a choice inside the graph" has always been the awkward part. The stock answer is a pile of Primitive boolean nodes and mask arithmetic, or leaving ten alternative paths wired in and hoping the model you didn't pick doesn't blow up. This node is the cleaner version: one input, up to 32 if == value branches, and a guaranteed fallback output. Feed it an INT or STRING, and it routes to exactly one output - the rest come back as ExecutionBlocker, which tells ComfyUI to skip those paths entirely.
That last bit is the whole trick. A node whose unselected outputs block execution isn't just cosmetic tidiness; the branches you don't hit literally never run. No wasted sampler steps, no missing-node errors from a path that should have been dead. It's the difference between a switch statement and a stack of ifs where every branch executes and you patch over the results.
How it works
Under the hood it's dead simple. The route() function parses your condition list from a hidden JSON field, compares condition against each entry in order, and the first match wins. It then builds all 33 outputs - if_1 through if_32 plus otherwise - sets the one selected output to your payload, and fills every other slot with an ExecutionBlocker. ComfyUI's executor sees that blocker and skips everything downstream of it. No requirements.txt, no models, nothing but the core comfy_execution.graph module that ships with ComfyUI.
The inputs that actually matter
condition(INT or STRING) - the value being tested. Feed it a prompt, an INT you got from elsewhere, whatever.compare_as-AUTOdoes integer comparison when both sides look like integers, and string comparison otherwise.INTandSTRINGforce a mode. Leave it onAUTOuntil you hit an edge case.conditions_json- the list of expected values, like["0", "1", "cat"]. The frontend hides this and edits it for you; you only touch it if the JS didn't load.string_trimandcase_sensitive- string-matching hygiene. Trim is off by default, so"cat"won't match" cat "until you flip it.passthrough(optional, any type) - the thing you actually want the chosen branch to receive. This is the important one: if you don't connect it, the selected output just emitsconditionitself. If you want an IMAGE, LATENT, MODEL, or CONDITIONING to flow down the chosen path, that goes inpassthrough.
The UI relabels outputs to if == 0, if == 1, and so on, with the last one named 否则 - the author's Chinese for "otherwise". Cosmetic, but worth knowing so you don't think your ComfyUI is glitching.
Installation
ComfyUI Manager, search "ComfyUI-IfBranchRouter", install, restart. Or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/Lingyuuuux/ComfyUI-IfBranchRouter
Then restart ComfyUI. That's it - no pip install step, no model downloads, nothing to break your existing environment. Given the dependency-hell reputation most custom nodes carry (see the ecosystem doc on why transformers version wars eat weekends), a zero-dependency logic node is refreshing.
Where people get burned
- Order matters. First match wins, so put the most specific condition first.
- AUTO mode and
"10.0": a string like10.5won't match an int branch, but10.0and"10"will. It parses floats that happen to be whole numbers. - The 32-branch cap is a hard ceiling; hit the "add" button past it and nothing happens.
- If the workflow loads but the outputs are all
if_1…if_32instead of labels, the frontend JS didn't load. Editconditions_jsonby hand - the format is just a JSON array.
Reach for this when you want one workflow to behave like several: a mode selector for SDXL vs. Flux, routing a prompt down a video path or an image path, A/B-ing samplers. It's a small node, but it's the kind of small node that makes big workflows actually maintainable.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| condition | INT,STRING | Value used by the if checks. INT and STRING values are supported. | |
| compare_as | COMBO | AUTO | AUTO compares as INT when both sides are integer-like, otherwise as STRING. |
| conditions_json | STRING | ["0", "1"] | Stored by the UI. Without the UI, edit this as a JSON array such as ["0", "1"]. |
| string_trim | BOOLEAN | false | Trim spaces before STRING comparison. |
| case_sensitive | BOOLEAN | true | When STRING comparison is used, match upper/lower case exactly. |
| passthroughopt | * | Optional value to pass through the selected branch. If omitted, the condition value is output. |
Outputs (33)
| Name | Type | Description |
|---|---|---|
| if_1 | * | — |
| if_2 | * | — |
| if_3 | * | — |
| if_4 | * | — |
| if_5 | * | — |
| if_6 | * | — |
| if_7 | * | — |
| if_8 | * | — |
| if_9 | * | — |
| if_10 | * | — |
| if_11 | * | — |
| if_12 | * | — |
| if_13 | * | — |
| if_14 | * | — |
| if_15 | * | — |
| if_16 | * | — |
| if_17 | * | — |
| if_18 | * | — |
| if_19 | * | — |
| if_20 | * | — |
| if_21 | * | — |
| if_22 | * | — |
| if_23 | * | — |
| if_24 | * | — |
| if_25 | * | — |
| if_26 | * | — |
| if_27 | * | — |
| if_28 | * | — |
| if_29 | * | — |
| if_30 | * | — |
| if_31 | * | — |
| if_32 | * | — |
| otherwise | * | — |