流程控制丨条件路由
A four-way switch for any data type, driven by booleans
- value
- fallback_value
- out1
- out2
- out3
- out4
- selected_index
- used_fallback
A switch node is how ComfyUI stops being a pipeline and starts being a program. QING_ConditionRouter is the QING pack's version: one any-typed input, four boolean conditions, four any-typed outputs. Depending on which condition is true, your value gets routed to the matching output. Wire a couple of boolean nodes upstream and you've got real branching in a graph that otherwise has no if-statements.
How it works
Inputs: value (any type - model, image, string, whatever), cond1 through cond4 (booleans), mode (the routing strategy), and an optional fallback_value. The three modes are worth understanding because they change the semantics:
- 首真命中 (first true, default) - the first true condition wins, in order 1→4.
- 优先级 (priority) - same behavior, intended for cases where conditions might overlap and you want a defined precedence.
- 多真报错 (all-true-error) - strict mode: if more than one condition is true it raises an error, forcing you to keep the conditions mutually exclusive.
Outputs: out1–out4 carry the value (only the selected one gets it; the rest are None), plus selected_index (INT, which output got it, or -1 if nothing matched) and used_fallback (BOOLEAN). If no condition is true, fallback_value lands on out1 and used_fallback reports it.
Because the sockets are the wildcard * type, you can route literally anything - that's the same escape hatch that makes every switch node work, per the KB's plumbing doc.
Where you'd reach for it
The classic wiring: MaskJudgment.has_mask → cond1, and route the same image to two branches - an inpainting path if the mask is real, the raw image if it isn't. Or QING_ImageQualityScore.pass → cond1 to send good frames to the upscaler and bad ones to a discard/retry branch. It's the "gate on a boolean" workhorse, and because outputs that don't match are None, downstream optional inputs just read them as "not connected" - which is exactly how the fallback pattern plays nicely.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/GAO-SHIQING/ComfyUI-QING
cd ComfyUI-QING
python install_dependencies.py
Restart ComfyUI after. The pack is one install covering 79 nodes; this one is pure logic with no extra dependencies. ComfyUI Manager: search "ComfyUI-QING." (The README's clone URL says GAOSHI-QING in one spot - that's a typo; the repo is GAO-SHIQING/ComfyUI-QING.)
Things to know
Unused outputs being None is the big one - if you read out2 while cond1 fired, you get nothing, so don't assume all four are always populated. The all-true-error mode is strict by design; if you hit its error, one of your upstream booleans is leaking true when you thought it was false. And there's no "else" branch as such - that's what fallback_value and used_fallback are for, so wire both when you want a guaranteed result rather than relying on downstream nodes tolerating a None.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| value | * | 任意输入值,将被路由到某一路输出 | |
| cond1 | BOOLEAN | false | — |
| cond2 | BOOLEAN | false | — |
| cond3 | BOOLEAN | false | — |
| cond4 | BOOLEAN | false | — |
| mode | COMBO | 首真命中 | 路由模式 |
| fallback_valueopt | * | 无命中时可选回退值 |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| out1 | * | — |
| out2 | * | — |
| out3 | * | — |
| out4 | * | — |
| selected_index | INT | — |
| used_fallback | BOOLEAN | — |