Nodes/TrentNodes/Number Counter
ComfyUI Node

Number Counter

The Counter That Actually Counts Between Runs

By TrentHunter82·Created 9 months ago·Updated 4 days ago· 36
Number Counter
    • number
    • float
    • int
    number_type
    mode
    start0.00
    stop100.00
    step1.00
    reset_bool0

    ComfyUI has a nasty habit of being stateless. Every run feels like a fresh start - your workflow runs, finishes, and nothing remembers where it left off. That's fine for one image, and a real problem when you're rendering 200 frames, iterating through a list, or numbering a batch. Number Counter is the stateful loop counter that fills the gap: it remembers its value between runs, on a per-node basis, and increments (or decrements) every time the queue fires.

    You'll reach for it whenever a workflow needs "the next number." Feed its int output into a filename, a prompt index, a text-file line index, or a frame offset, and each queue run steps forward instead of repeating itself. The author of this pack clearly hits this constantly - it's one of several little "Cowboy" utilities that exist to make per-clip and per-batch pipelines not miserable.

    How it works

    The counter lives in the node instance and is keyed by the node's unique id, so the counter state survives across runs for that node. Each execution it walks the mode logic:

    • increment / decrement - step by step from start, forever.
    • increment_to_stop / decrement_to_stop - step but stop at stop.
    • reset_after_stop - step to stop, then snap back to start and start over.

    The start, stop, and step fields are floats, but you pick the output flavor with number_type (integer truncates, float doesn't). There's also a reset_bool input - wire a truthy value into it and the counter resets to start on that run, which is your clean way to rewind a batch pipeline without touching the widgets.

    Three outputs, same value in three types: number (NUMBER, the polymorphic kind that slots into any number socket), float, and int. Grab whichever your downstream node wants; you usually only wire one.

    One thing worth knowing: the node forces itself to re-run every execution (the IS_CHANGED trick that returns NaN). That's exactly what you want here - a counter that only fires "when its inputs changed" would never count. But it's also why you should keep this node out of the hot path of a huge graph; an always-dirty node defeats ComfyUI's caching for everything upstream of it.

    Install

    Search "Trent Nodes" in ComfyUI Manager, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/TrentHunter82/TrentNodes.git
    cd TrentNodes
    pip install -r requirements.txt
    

    This node needs nothing beyond the pack's base Python requirements - it's pure arithmetic. Restart ComfyUI after installing. (If Manager balks at the pack - the author has noted an early repo rename caused a duplicate-registry flag - the manual clone is the reliable route.)

    Common issues

    • "It reset when I changed the workflow." The counter is keyed by node id. Duplicate the node and it starts a fresh counter; delete and re-add it and the state starts over. That's expected, not a bug.
    • Integer truncation surprises. start/step are floats; with number_type set to integer you get int(start + k*step), so a step of 0.5 produces 0, 0, 1, 1... Set step to whole numbers for whole-number sequences.
    • Counting on the wrong run. Because ComfyUI caches backward from output nodes, "one queue run" isn't always one execution of everything. If your counter jumps by more than one per run, something upstream is being re-executed each time.

    For batch numbering, frame indexes, and prompt-list iteration, this is the node. Just remember what it is: a live counter with memory, not a deterministic pure function - which is precisely why it's useful, and precisely why it should stay on its own little branch.

    CategoryTrent/Utilities

    Inputs (6)

    NameTypeDefaultDescription
    number_typeCOMBO2 options: integer, float
    modeCOMBO5 options: increment, decrement, increment_to_stop, decrement_to_stop, reset_after_stop
    startFLOAT0.00-1000000000000000000–1000000000000000000
    stopFLOAT100.00-1000000000000000000–1000000000000000000
    stepFLOAT1.000–1000000
    reset_booloptNUMBER0

    Outputs (3)

    NameTypeDescription
    numberNUMBER
    floatFLOAT
    intINT