switch/case
The pick-an-option node
- case_0
- default
- result
Some workflows need "pick one of several options based on a number" - a computed index that decides between three prompt styles, two models, four resolutions. You could build that with a pile of if/else nodes. Or you could use switch/case, which is exactly Python's switch-style selection: feed it an index, get back the matching value.
It's one of the flow-control nodes in Basic data handling, StableLlama's dependency-free utility pack. And yes - there's a catch up front. The author's own description carries a note: this version of the node will most likely be deprecated in the future. The pack is actively evolving its control-flow family, so learn the pattern here but don't be shocked if the newer flow-select nodes are what replace it.
How it works
You give it a select integer and a list of case inputs (case_0, case_1, ...), with a default as a safety net. It returns the case matching your index; if the index is out of range, you get default. Under the hood the case inputs are dynamic (you add more with a "+" button), and the node uses lazy evaluation - it only asks ComfyUI to compute the one case you actually selected, not all of them. That's a real efficiency win when your cases are expensive (a whole model load, say): the unselected branches never even evaluate.
The inputs and the output
select(INT, default 0, min 0) - the index. Wire it from a counter, a random node, a comparison, anything that produces an int. Index 0 =case_0, index 1 =case_1, and so on.case_0(ANY, dynamic) - the first option. Add more cases with "+". Values can be prompts, numbers, conditioning - whatever the downstream expects.default(ANY, optional) - returned whenselectis out of range. Leave it unconnected and out-of-range returnsNone, which is usually a bug you want to catch, not a silent pass.result(output, ANY) - the chosen value.
Installing it
Install Basic data handling via ComfyUI Manager (search "Basic data handling"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/StableLlama/ComfyUI-basic_data_handling
Restart ComfyUI. No Python dependencies, no models to download - one of the cleanest installs in the ecosystem.
Troubleshooting
- "It always picks case 0." Then
selectis 0 - check what's actually wired into it. Ifselectcame from a node whose output is a float or a string, ComfyUI may be coercing it in a way you didn't expect (a"1"string and an1int are different). Cast it to INT explicitly with the pack'sto INTnode before it reachesselect. - "Out of range gives me garbage." You left
defaultunconnected, so you gotNonedownstream and it did something weird. Always connect adefaultwhen you can't guarantee the index range. - "I want a condition, not an index." Then you want
if/elif/else, which branches on booleans. SwitchCase is for the "choose by number" case specifically - and remember it's flagged for future deprecation, so if you're building something long-lived, keep an eye on the pack's changelog.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| select | INT | 0 | — |
| case_0 | * | — | |
| defaultopt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | * | — |