Lazy Index Switch | akatz-loops
Ten Inputs, One Output, Chosen by an Index — Without Computing the Losers
- value0
- value1
- value2
- value3
- value4
- value5
- value6
- value7
- value8
- value9
- *
You've got up to ten things - ten models, ten prompts, ten different image pipelines - and you want one of them active, selected by an integer. That's LazyIndexSwitch: an index (0–9) and ten value0–value9 inputs in, one * output out, passing through whichever value the index points at. It's the multi-way version of a switch node, and it's "lazy" in the precise ComfyUI sense: the branches you don't select are never evaluated.
That laziness is the whole point, and it's worth saying plainly because it changes how you use the node. An ordinary switch has to receive all its inputs already computed - which means if you build a "pick one of three models" switch the naive way, all three models load anyway and you've saved nothing. A lazy switch declares its inputs as optional-until-needed, so ComfyUI only executes the upstream of the selected branch. Wire ten expensive pipelines into value0–value9 and only the one the index lands on actually runs. That's the difference between a switch that saves you VRAM and one that's just cosmetic. (It's also why the pack's lazy switches show up in community discussion around big workflows - they prune what doesn't execute.)
The inputs that matter
- index (default
0, 0–9) - the selector. Zero-based, sovalue0is index 0. Convert it to an input and drive it from a loop counter, a seed, or an external value, and the graph picks its branch dynamically. - value0 - required (there has to be a first one).
- value1 through value9 - optional. Each is
*, so any type works: models, images, latents, strings, conditioning.
The output is * and carries the chosen value's type through, so the socket adapts to whatever the branch actually was.
Where it fits in this pack
The natural pairing is with the loop/list machinery: a IntegerListGeneratorNode emits a list of indices, a GetIntFromList picks one per iteration, and LazyIndexSwitch routes the graph to the matching branch. That turns "I want to try my workflow with three different settings" into one run that walks the list. And because it's a lazy switch, you can stack it with expensive branches (multiple model loaders, multiple ControlNet stacks) without paying for all of them each run.
One known wart from the field: on recent ComfyUI builds, large workflows that nest subgraphs and lazy switches together can throw a maximum recursion depth exceeded error during prompt validation. The confirmed community workaround is ComfyUI-GraphConstantFolder - drop it in custom_nodes, restart, no settings needed. If you hit that error, it's the validator, not your switch logic.
Install
Part of Akatz-Loop-Nodes (akatz-ai). Via ComfyUI Manager, search "Akatz-Loop-Nodes"; or:
cd ComfyUI/custom_nodes
git clone https://github.com/akatz-ai/Akatz-Loop-Nodes
Restart ComfyUI. The pack's only dependency is opencv-python (image nodes), no models. The custom_nodes.ComfyUI-Execution-Inversion module path on listings is lineage from BadCafeCode's execution-inversion demo - not a separate install.
The one real trap is index out of range: index is capped at 9 and value9 is the last socket. Ask for 10 and there's no branch to route to. Keep your index within 0–9 and, if you're driving it from a loop, clamp it before it reaches the node.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| index | INT | 00–9 | — |
| value0 | * | — | |
| value1opt | * | — | |
| value2opt | * | — | |
| value3opt | * | — | |
| value4opt | * | — | |
| value5opt | * | — | |
| value6opt | * | — | |
| value7opt | * | — | |
| value8opt | * | — | |
| value9opt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| * | * | — |