Number Counter
The Counter That Actually Counts Between Runs
- number
- float
- int
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 bystepfromstart, forever.increment_to_stop/decrement_to_stop- step but stop atstop.reset_after_stop- step tostop, then snap back tostartand 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/stepare floats; withnumber_typeset tointegeryou getint(start + k*step), so a step of 0.5 produces 0, 0, 1, 1... Setstepto 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.
Inputs (6)
| Name | Type | Default | Description |
|---|---|---|---|
| number_type | COMBO | 2 options: integer, float | |
| mode | COMBO | 5 options: increment, decrement, increment_to_stop, decrement_to_stop, reset_after_stop | |
| start | FLOAT | 0.00-1000000000000000000–1000000000000000000 | — |
| stop | FLOAT | 100.00-1000000000000000000–1000000000000000000 | — |
| step | FLOAT | 1.000–1000000 | — |
| reset_boolopt | NUMBER | 0 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| number | NUMBER | — |
| float | FLOAT | — |
| int | INT | — |