ComfyUI Node

Batch Index Counter

The little counter that feeds the rotation loaders

By trunksn1·Created 10 months ago·Updated 3 months ago· 1
Batch Index Counter
    • batch_index
    • info
    actionincrement
    counter_iddefault
    set_value0
    increment_by1

    The plumbing between you and the loader

    BatchIndexCounter doesn't generate anything - it's a stateful number the rotation nodes can watch. Its only job is to hand CheckpointRotation Loader (Advanced) a batch_index that actually moves, because that loader only switches checkpoints when its batch_index input changes. Static graph, static index, no rotation. This counter is how the index gets to move.

    The README's basic workflow wires it up in two clicks: set action to increment, connect its batch_index output to the loader's batch_index input, and each execution advances the count. You also get an info string ("Counter 'default' incremented to 3") that's handy if you drop it into a text preview node.

    How it works

    State lives in a class-level dictionary keyed by counter_id. Three actions:

    • increment - adds increment_by (default 1) to the counter.
    • set - forces the counter to set_value.
    • reset - zeroes it.

    Because counters are keyed by counter_id, you can run several independent ones in one graph: a "main" counter for checkpoint rotation and a "secondary" one stepping by 2 for a faster cycle, each tracked separately. That's the genuinely useful part of this node.

    The two things to know

    State is shared, not per-node. The dictionary is a class variable, so two copies of the node using the same counter_id are the same counter. If you duplicate the node expecting isolation, you won't get it - give the second copy a different counter_id. And because the state lives in Python memory, a full ComfyUI restart starts every counter back at zero, but a normal re-queue does not.

    It only ticks when ComfyUI actually re-runs it. There's no IS_CHANGED on this node, so if its inputs are frozen and the graph is sitting there, ComfyUI will happily cache the output and the counter won't advance. In practice that's fine because you're driving it from a loop or a graph that changes per iteration - which is exactly the setup the rotation nodes demand anyway. If your counter seems stuck at the same number, check that the workflow around it is actually re-executing, not that the counter is broken.

    When you'd reach for it

    Honestly, only in the explicit-batch_index style of workflow that uses the Advanced loader. The pack's star node, Checkpoint Rotation (Batch), gets its count from a Primitive INT with control_after_generate: increment instead, and the Simple loaders hide the counter entirely. So BatchIndexCounter is the middle path: you want the advanced loader's modes and filter, but you don't want to fiddle with Primitive widgets. It's a utility, it does one thing, and when you need that one thing it's exactly right.

    Install

    It's part of the pack, so there's nothing extra to install beyond the clone:

    cd ComfyUI/custom_nodes/
    git clone https://github.com/trunksn1/comfyui-change-checkpoint-randomly
    

    Restart ComfyUI and look for [ComfyUI] Checkpoint Rotation Node loaded successfully! in the console. No dependencies beyond ComfyUI itself. It shows up under Add Node → utils → Batch Index Counter, next to its sibling Simple Counter.

    Categoryutils

    Inputs (4)

    NameTypeDefaultDescription
    actionCOMBOincrementAction to perform on the counter
    counter_idoptSTRINGdefaultUnique ID for this counter (allows multiple independent counters)
    set_valueoptINT00–1000000Value to set when action is 'set'
    increment_byoptINT11–1000Amount to increment by

    Outputs (2)

    NameTypeDescription
    batch_indexINT
    infoSTRING