Nodes/ComfyUI-Apt_Preset/flow_stage_index_switch
ComfyUI Node

flow_stage_index_switch

A gate that only lets the active stage's branch through

By cardenluo·Created 2 years ago·Updated a day ago· 324
flow_stage_index_switch
  • any_input
  • any_output
stage_index1
open_stage_index1

In a staged workflow, sometimes stage 2 shouldn't do the same thing as stage 4. That's the entire reason flow_stage_index_switch exists: it's a per-stage gate. Wire whatever you want routed into any_input, and the node passes it through - but only when the current stage_index equals your open_stage_index. Any other stage gets an execution blocker, which means that whole downstream branch simply doesn't run.

How it works

The clever part is that it's lazy - it doesn't even ask its upstream for the input unless it's about to pass it through. Look at the source: check_lazy_status only requests any_input when stage_index == open_stage_index and the input is still missing. So a blocked branch isn't just muted, it's never computed at all. That's a real saving when the blocked branch would otherwise have been, say, a second sampler or a ControlNet stack sitting idle.

When the gate does open, it returns any_input unchanged. When it's closed, it returns an ExecutionBlocker(None) - the standard ComfyUI idiom for "skip everything downstream of me." It's a switch in the same family as the classic A/B and fallback switches covered in the node-plumbing layer, except the selector isn't a boolean or a priority order, it's the pack's own flow-stage counter.

Inputs

  • stage_index - the current stage number (wire it from the same stage_index output of flow_stage_begin, or it defaults to 1).
  • open_stage_index - the stage you want to let through.
  • any_input - the wildcard * input; it'll carry a model, a latent, a prompt string, whatever.

The output is any_output, same type, nothing transformed.

Where you'd actually use it

Say you have a 3-stage H3 pipeline where only stage 1 needs a ControlNet pass and stages 2–3 run clean. You put a flow_stage_index_switch with open_stage_index = 1 in front of the control branch, and it drops out of the graph on every other stage. Or invert it - open_stage_index pointing at the final stage lets you run a one-time post-process (a save node, a final upscale) only at the end, instead of on every segment. Because it's lazy, you can build these gates into a workflow without paying for the dead branch on every run.

Install

Part of ComfyUI-Apt_Preset - ComfyUI Manager → "ComfyUI-Apt_Preset", or clone into custom_nodes + install.bat. No models, no deps beyond the pack's own requirements.txt. The only real gotcha is remembering that this gates execution, not data - if you wanted a fallback that picks the first non-empty value, that's a different node (rgthree's Any Switch, or this pack's flow_BooleanSwitch). This one is purely "am I the active stage?"

CategoryApt_Preset/flow

Inputs (3)

NameTypeDefaultDescription
stage_indexINT11–10000
open_stage_indexINT11–10000
any_inputopt*

Outputs (1)

NameTypeDescription
any_output*