ComfyUI Node Runs on cloud

Switch (Any)

Pick one of many inputs with a number, run only that branch

By ltdrdata·Created 3 years ago·Updated 4 months ago· 3,248
Switch (Any)
  • input1
  • selected_value
  • selected_label
  • selected_index
select1
sel_modefalse

Switch (Any) is a selector: feed it several inputs, set a number, and it passes through the one you picked. It takes any type - images, latents, models, conditioning, whatever - and figures out its type from the first thing you connect. The input slots grow as you fill them, so there's no fixed cap on how many options you can wire in. One integer chooses which one flows out.

This is the node for A/B testing and branch selection without rewiring. Instead of dragging cables around every time you want to try checkpoint B instead of A, or run the "upscale" path instead of the "quick preview" path, you wire both into a Switch and flip a number. And because Impact Pack's switches are built on ComfyUI's execution-model inversion, the branches you didn't select don't execute - so the unused path costs you no compute, which is the part that makes this more than cosmetic.

How it works

The node starts with one optional input slot and adds another each time you connect one, so you build up input1, input2, input3… as needed. The select integer indexes which slot passes to the output - select of 2 emits whatever's on input2. Its type is decided the moment you plug something in; after that, the other slots expect the same type. The lazy-evaluation piece is the important bit: with execution inversion, only the chosen branch's upstream nodes actually run. Wire an expensive upscaler into input2 and a cheap passthrough into input1, leave select at 1, and the upscaler never fires.

The inputs and outputs that matter

  • select (default 1) - which input to pass through, by number. This is the dial. It's 1-indexed, so select 1 is the first slot.
  • sel_mode (default false) - controls when the selection is read. Off is the normal, stable behavior; the toggle exists for cases where you want the select value re-evaluated per-run rather than cached. Leave it off unless you have a reason.
  • input1 … (optional, any type) - the candidate inputs. Connect one and a new empty slot appears. The first connection fixes the type for the rest.

Outputs:

  • selected_value - the chosen input, passed through. This is the one you wire onward.
  • selected_label - the name/label of the selected slot, as text.
  • selected_index - the index that was selected, as an integer. Handy for logging or driving other logic.

How to install it

Install the pack via ComfyUI Manager (search ComfyUI Impact Pack, install, restart), or manually:

cd ComfyUI/custom_nodes
git clone https://github.com/ltdrdata/ComfyUI-Impact-Pack comfyui-impact-pack
cd comfyui-impact-pack
python -m pip install -r requirements.txt   # ComfyUI's python; python_embeded on portable

then restart. No models - it's a graph utility.

Common issues & troubleshooting

"The first input must be provided." The pack's switches require the first slot to be connected; the rest are optional. If select points at a slot that isn't wired, you'll get an error - connect that input, or point select at one that exists.

Type validation complains even though it works. Expected. The node uses a wildcard type so it can carry anything, and ComfyUI's validator sometimes flags that mismatch cosmetically. If it runs, ignore the message - the pack documents this as a known limitation until ComfyUI ships proper dynamic types.

I want to route one input to many outputs, not many to one. That's the opposite node - Inversed Switch (Any) takes a single input and sends it to one of several outputs. Use that when you're distributing, this when you're selecting.

Not sure whether to use this or rgthree's fast group muters. Different jobs. Switch picks a data branch by number; rgthree's group muters toggle whole regions of the graph on and off. For "which of these two models," Switch is cleaner; for "disable this entire section," reach for the muters.

CategoryImpactPack/Util

Inputs (3)

NameTypeDefaultDescription
selectINT11–999999The input number you want to output among the inputs
sel_modeBOOLEANfalseIn the case of 'select_on_execution', the selection is dynamically determined at the time of workflow execution. 'select_on_prompt' is an option that exists for older versions of ComfyUI, and it makes the decision before the workflow execution.
input1opt*Any input. When connected, one more input slot is added.

Outputs (3)

NameTypeDescription
selected_value*Output is generated only from the input chosen by the 'select' value.
selected_labelSTRINGSlot label of the selected input slot
selected_indexINTOutputs the select value as is