Nodes/ComfyCollectorNodes/Gated Increment (CCN)
ComfyUI Node

Gated Increment (CCN)

An integer that changes every N runs, and remembers it across restarts

By valkymaera·Created 4 months ago·Updated 10 days ago· 1
Gated Increment (CCN)
    • INT
    value0
    rate5
    mode
    timing
    step1
    reset_counterfalse
    debugfalse

    Every ComfyUI user eventually wants a counter. You're doing a grid of seeds, a sweep of steps, an image-by-index tour through a folder, and you need something that spits out a new number on a schedule without you touching the graph. Gated Increment is that, with one feature most counter nodes lack: it remembers where it was across ComfyUI restarts, because it stores its state in a JSON file next to the node code. Quit, relaunch, and the count picks up where it left off.

    The node tracks an internal run counter. Every execution it ticks up; when it reaches rate runs, the output value changes and the counter resets. Two knobs shape the change: mode (increment adds step each time, random rolls a fresh random integer), and timing (before means the changed value is this run's output; after means this run gets the old value and the widget updates for the next one - same trap as ComfyUI's control_after_generate, so before is usually what you want for a sweep).

    The inputs that matter

    • value - the current integer. Wire it in or just read it off; the node emits it back out (possibly changed).
    • rate - runs between changes. Default 5, min 1. This is the "gated" part: nothing happens until the run count hits the threshold.
    • mode / timing / step - how it changes and when. The three you'll actually set.
    • reset_counter - a one-shot reset. Toggle it on, run once, toggle it back off, and the run counter is back to zero. Not the most discoverable reset in the world, but it works.

    It's marked as an output node, so it runs every queue even with nothing downstream - and it uses the classic IS_CHANGED → NaN trick from the plumbing playbook to defeat ComfyUI's cache and guarantee it fires each run. That also means it always runs, which is exactly what a counter needs.

    A caveat about where it lives

    Gated Increment is one of the pack's wip (work-in-progress) nodes. Those live in the wip/ folder, which is excluded from the registry-published package but ships with a git clone. In practice this matters little because both install paths below are git clones, but it means the node appears under the CCN/utils category with a slightly more experimental pedigree than the stable nodes. If you installed from the Comfy Registry package instead, you might not see it - clone from git to be safe.

    cd ComfyUI/custom_nodes
    git clone https://github.com/valkymaera/ComfyCollectorNodes
    

    restart, and it's there. ComfyUI Manager's install of ComfyCollectorNodes does the same clone, so it works too.

    Wiring it into a sweep

    Feed its INT output into an Image Loader By Index, a seed, or a Float Lerp's t, set rate to the number of images you want per value, and each run steps the index forward while the counter is quiet. Persistence means an interrupted batch doesn't lose its place - rerun the workflow and it resumes at the same index. It's a small tool, but it's the difference between babysitting a batch and walking away from it.

    CategoryCCN/utils

    Inputs (7)

    NameTypeDefaultDescription
    valueINT0-9007199254740991–9007199254740991
    rateINT51–1000000Number of runs between each value change.
    modeCOMBO2 options: increment, random
    timingCOMBO2 options: before, after
    stepINT11–1000000Amount to add in increment mode.
    reset_counterBOOLEANfalseReset the run counter to 0. Toggle on, run once, toggle off.
    debugBOOLEANfalse

    Outputs (1)

    NameTypeDescription
    INTINT