ComfyUI Node

Dynamic Switch Any Node

An any-type switch that only runs the branch you pick

By inkbottle-9·Created 8 months ago·Updated 12 days ago· 1
Dynamic Switch Any Node
  • default
  • result
index0
cases_count2

Pick one of several inputs by number. That's the whole job, but there are two different things people mean by "switch" in ComfyUI, and this is the less common one. rgthree's Any Switch is a fallback: it walks its inputs and passes the first non-null one, no selector, the graph decides. This node is an A/B selector: you hand it an index, it hands you back the case at that slot. Different muscle, different use.

You wire it in anywhere you want to flip between a handful of things without rewiring - two model loaders, a batch of prompts, a set of different conditioning. Feed the index from a saved primitive to lock a choice, or chain it after a random node to cycle through options on every run.

Why it's better than a plain switch

The interesting part is hidden: this node is lazy. Its dynamic case_0, case_1, … inputs are only evaluated when the node actually asks for them. In practice that means when you select case 2, case 0 and case 1 don't execute upstream at all. That's a genuinely useful trick when the branches are expensive - e.g. three different checkpoint loaders sitting on a low-VRAM card, where a non-lazy switch would load every model every run. Only the branch you point at does work, and the default input is equally lazy: it only runs when the index is out of range.

The trade-off cuts the other way too: if you expect an unselected branch to have run (a node that saves files, say), it won't. Lazy means skipped, and skipped means no side effects. That's usually what you want from a selector; just don't put output nodes on dead branches and expect them to fire.

Inputs and outputs

  • index - which case to return, from 0 to cases_count - 1. Out of range (including negative) returns default.
  • cases_count - how many case_* ports exist (0–100). Bump it and new ports appear.
  • default (optional) - value returned when nothing matches. Leave unwired and out-of-range gives you None.
  • result - the output. Type *, so it'll take a model, a latent, a string, whatever - a switch doesn't care what it's routing.

Common gotchas

  • The case_* and default ports are lazy and only appear when cases_count says so. If you set cases_count to 3, you get case_0..case_2. A workflow that references case_4 will trip over a missing input until you bump the count.
  • Out-of-range is silent. index = 5 on a 3-case node doesn't error - you just get default, which is None if you didn't wire one. If your workflow "randomly does nothing," check the index against the count.
  • It's not a first-non-null fallback. If you want "use this unless that's connected," that's rgthree's Any Switch, not this node. This one only ever returns exactly what you point at.
  • Whole pack install. It ships in comfyui_dynamic, a zero-dependency solo pack, so it comes along with the script executor whether you want it or not:
cd ComfyUI/custom_nodes
git clone https://github.com/inkbottle-9/comfyui_dynamic.git

then restart, or grab comfyui_dynamic through ComfyUI Manager. Small pack, honest rough edges, but this node is solid - it's the one in the pack I'd actually miss if it were gone.

Categorydynamic/utils

Inputs (3)

NameTypeDefaultDescription
indexINT0-1–100The index of the case to return. Must be between 0 and cases_count - 1, else the default value will be returned.
cases_countINT20–100The number of cases for this node. Must be between 0 and 100.
defaultopt*The default value to return if no cases match. None if not specified.

Outputs (1)

NameTypeDescription
result*The value of the case at the specified index.