Nodes/Yaser-nodes for ComfyUI/๐Ÿ”€ Switch (Any) - Yaser
ComfyUI Node

๐Ÿ”€ Switch (Any) - Yaser

The switch node that grows its own inputs (and only runs the branch you pick)

By YaserJaradehยทCreated about a year agoยทUpdated 11 months agoยท 8
๐Ÿ”€ Switch (Any) - Yaser
  • input1
  • selected_value
  • selected_label
  • selected_index
โ—„select1โ–บ
โ—„sel_modefalseโ–บ

You know the pain: you want one workflow that can generate a portrait or a landscape, a raw image or the processed one, checkpoint A or checkpoint B. Vanilla ComfyUI makes you build the whole pipeline twice and flip between halves with mute/bypass groups. The Switch (Any) - Yaser node is the cleaner answer: one node, any number of inputs, and a single integer that decides which one flows through.

Drop it into a graph and it's unassuming - one input1 slot. Connect a cable to it and a second input2 slot materializes. Connect that and input3 appears. The web-side JavaScript (web/js/dynamicInputs.js) is what does the growing, and it propagates the type of whatever you plug in, so you can route images, latents, models, text, or conditioning through the same node. That "any type" support is the whole trick: it's built on the AnyType("*") pattern, which is how all the good generic switches in this ecosystem work.

Why it's better than a dumb any-switch

Under the hood this is a port of ImpactSwitch from the Impact Pack, which is one of the most battle-tested pieces of ComfyUI infrastructure around. The part that matters to you is lazy execution: the node implements check_lazy_status, which tells ComfyUI exactly which input the current select value needs. ComfyUI then skips computing every other branch of your graph. That's not a nice-to-have - a heavy unselected branch (a whole second img2img pass, say) simply doesn't run. Cheap switches that pull in all inputs first will happily decode, upscale, and sample work you then throw away.

The inputs that matter

Only two of these are widgets; everything else is a cable:

  • select (INT, default 1) - which input to pass through. Note it's 1-based: select = 1 outputs input1, select = 2 outputs input2. The README claims 0-based indexing, but the code (input{selected_index}) and the dynamic slot naming disagree. Trust the node, not the README.
  • sel_mode (BOOLEAN) - select_on_execution (default) means the pick is evaluated when the workflow actually runs, which is what you want if select is wired from another node. select_on_prompt exists for older ComfyUI and decides before execution. Leave it on the default unless something breaks.

It outputs selected_value (whatever you routed), selected_label (the string name of the chosen slot, handy for debugging), and selected_index (just echoes select back).

Installing

The whole pack comes at once - there's no standalone install for this node:

cd ComfyUI/custom_nodes
git clone https://github.com/YaserJaradeh/comfyui-yaser-nodes.git

then restart ComfyUI. Or use ComfyUI Manager and search for "Yaser-nodes". The pack has a requirements.txt, but these specific nodes only need what ComfyUI already ships.

Where people get burned

  • The select widget's max doesn't auto-grow on the canvas until you reconnect something - if your workflow loads with select = 5 but only three inputs are connected, the value clamps and you get nothing out. The JS tries to fix this on load and paste, but if a saved workflow looks dead, check the widget.
  • API mode is not guaranteed. The node needs extra_pnginfo to resolve slot labels, and the code logs a warning that it can't promise correct behavior when driven through the API rather than the UI. If you're scripting ComfyUI, prefer a plain index switch.
  • It refuses connections to Reroute nodes by design (inherited from Impact Switch) - if a cable won't snap, that's why.

It's not a switch you'll write about, but it's one you'll reach for constantly once it's in your kit.

Categorylogic/switch

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