Nodes/WAS Node Suite v3/Any Index Switch
ComfyUI Node Runs on cloud

Any Index Switch

Pick one of many inputs with a number

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Any Index Switch
  • index
  • input_a
  • input_b
  • input_c
  • input_d
  • input_e
  • input_f
  • input_g
  • input_h
  • input_i
  • input_j
  • input_k
  • input_l
  • input_m
  • input_n
  • input_o
  • input_p
  • input_q
  • input_r
  • input_s
  • input_t
  • input_u
  • input_v
  • input_w
  • input_x
  • input_y
  • input_z
  • output
  • resolved_index
  • count
out_of_rangewrap

The A/B switch handles two options. Real life hands you five. Any Index Switch is the answer to "which of these N values do I want?" - you drive a number and it passes the matching input, whatever type those inputs are. Wire a counter or a loop index into it and a single switch becomes a rotating stage that steps through its inputs one run at a time.

Under WAS Suite/Logic/Switch, it takes up to 26 candidate inputs (input_a through input_z) of any type, plus an index. The output is the chosen input, and the whole thing types itself the way the other WAS switches do: first connection fixes the type, unconnected slots aren't counted. So if you wire only input_a, input_b, and input_c, index 0 is input_a, not the visually first slot on the node.

The index rules worth memorizing

  • It counts from 0. input_a = 0, input_b = 1, and so on. This trips people whose muscle memory says "first = 1."
  • Negative indices count from the end. -1 is the last connected slot. Handy when you don't know how many are wired.
  • Decimals are truncated. 2.7 becomes 2, so you can drive it straight from a float if that's all you have.
  • Out of range is your choice. With three slots and index 4: wrap wraps around to slot 1, clamp pins to the last slot (slot 2), error stops the prompt and tells you. wrap is the right default for a looping stepper; error is the one you want when a wrong index means a bug you'd rather hear about than silently round into.

Like the other switches in the suite, only the selected input is evaluated - the work behind the other 24 candidate branches is skipped, so you can park genuinely heavy pipelines behind different slots and only pay for the one the index points at.

The outputs that make it a stepper

output is the obvious one. The other two are what turn the node into something programmable:

  • resolved_index - which slot was actually read after wrap or clamp did its thing. Feed it back into your logic to keep a counter in sync when it runs past the end.
  • count - how many slots are connected. A stepper that increments its own index forever needs to know when to reset, and this is that number.

The natural pairing: Condition Chain → index switch

The pattern the node description points at is the classic if/else chain. Run WAS Condition Chain - which answers the position of the first true condition - straight into this switch's index, and you've built a readable if/else-if/else ladder out of two nodes. Condition A holds → index 0 → input_a answers; condition B holds → index 1 → input_b answers; nothing holds → the chain's fallback → whichever slot you've reserved for the else case. It's the closest ComfyUI plumbing gets to a switch statement, and it stays legible because each branch is still a visible wire.

Installing

Part of WAS Node Suite v3 (WASasquatch/was-node-suite-comfyui), WASasquatch's MIT suite - going since 2023, one of the packs that's been an ecosystem staple since the early days. Logic nodes need nothing extra: no packages, no weights. Requires ComfyUI 0.14.0+ - v3 is written against the newer node backend API, so on an older ComfyUI the whole pack silently fails to register.

Via ComfyUI Manager, search WAS Node Suite v3, or clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui

Restart and it shows up under WAS Suite/Logic/Switch. Missing? Update ComfyUI - it's almost always the version, not the install.

CategoryWAS Suite/Logic/Switch

Inputs (28)

NameTypeDefaultDescription
indexINT,NUMBER,FLOAT0-99999999–99999999Slot to pass on, from 0. Negative counts from the end: -1 = last. A decimal is truncated: 2.7 = 2.
out_of_rangeCOMBOwrapIndex outside 0..count-1. With 3 slots and index 4: `wrap` = slot 1, `clamp` = slot 2, `error` stops the prompt.
input_aoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_boptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_coptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_doptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_eoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_foptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_goptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_hoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_ioptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_joptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_koptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_loptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_moptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_noptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_ooptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_poptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_qoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_roptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_soptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_toptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_uoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_voptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_woptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_xoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_yoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.
input_zoptCOMFY_MATCHTYPE_V3One candidate for the index. Any type. The first connection fixes the type; an unconnected slot is not counted, so index 0 is the first slot actually wired.

Outputs (3)

NameTypeDescription
outputCOMFY_MATCHTYPE_V3The selected input, typed to whatever was connected.
resolved_indexINTSlot actually read, from 0, after wrap or clamp.
countINTConnected slots. The index runs 0..count-1.