Nodes/ComfyUI-nhknodes/πŸ”„ Cycling Switch (nhk)
ComfyUI Node

πŸ”„ Cycling Switch (nhk)

Rotate Through Prompts Automatically β€” Cycling Switch (nhk)

By EnashkaΒ·Created 12 months agoΒ·Updated 28 days agoΒ· 23
πŸ”„ Cycling Switch (nhk)
    • output
    • info
    • current_index
    • executions_on_input
    β—„resetfalseβ–Ί
    β—„stay_count1β–Ί

    Cycling Switch (nhk) rotates through an unlimited number of connected inputs, one per execution - or one every N executions, if you set stay_count - then loops back to the start. It's the "automatic prompt variation" machine: connect ten different prompts, run a batch, and every run uses a different one without you touching the graph.

    This is the node people ask for on r/comfyui when they want to "vary my prompt every X images during a batch" - testing a batch of prompts, cycling through models, rotating LoRA setups, or flipping between several seeds. It's also the natural driver for the pack's own Text Template: wire template slots to this switch and you get fill-in-the-blanks variation on autopilot. Any node with a STRING, INT, or any-typed input can be fed from the cycle.

    How it works

    The node uses dynamic inputs - connect a wire and another socket appears, up to however many you want. On each execution it picks the current input by index, then increments an internal counter. stay_count (1–100, default 1) is how many consecutive executions each input gets before the switch advances; set it to 10 and each of your ten prompts runs ten times before the next one starts, which is precisely the "10 images per variation" pattern people describe wanting.

    Two details make it behave well in practice. IS_CHANGED returns NaN, forcing a re-execution every queue run so the cycle actually advances (a naive switch would get cached and never move). And it auto-resets to the first input if you connect or disconnect wires - the input count changing invalidates the cycle, which prevents out-of-bounds errors. A reset boolean forces the same reset manually.

    The outputs give you the selected value plus telemetry: output (the chosen input), info (a human-readable "using input 2 of 5, execution 3/10" string), current_index (1-based), and executions_on_input (how many runs the current input has had). If you need to know which prompt is live - say, to name a file - wire current_index or info to a filename builder.

    Inputs and outputs

    • reset - boolean, default false. Manually reset the cycle to input 1.
    • stay_count - INT, 1–100, default 1. Runs per input before switching.

    Outputs: output (*), info (STRING), current_index (INT), executions_on_input (INT).

    Installing it

    Part of ComfyUI-nhknodes:

    cd ComfyUI/custom_nodes && git clone https://github.com/Enashka/ComfyUI-nhknodes
    

    restart, or "NHK Nodes" from ComfyUI Manager. No extra deps.

    The caveat that catches people

    Because it's stateful, the cycle depends on the order runs execute in - if a rerun or a partial failure re-executes the switch mid-cycle, the count can drift, and the switch doesn't persist across a ComfyUI restart (it starts back at input 1). For pure batch runs in one sitting, none of that bites. For anything where you need the cycle to survive restarts or be perfectly deterministic across reruns, you'll want to reset explicitly or keep the state elsewhere. Used as intended - set stay_count, queue a batch, walk away - it's the smoothest way to get variation without babysitting the queue.

    Categorynhk/utility

    Inputs (2)

    NameTypeDefaultDescription
    resetBOOLEANfalseReset cycle back to first input
    stay_countINT11–100Number of executions to stay on each input before switching

    Outputs (4)

    NameTypeDescription
    output*β€”
    infoSTRINGβ€”
    current_indexINTβ€”
    executions_on_inputINTβ€”