ComfyUI Node

计数器

The Counter That Survives Re-Runs (File Names, Loops, Done Right)

By 1H-hobit·Created about a year ago·Updated 11 months ago· 2
计数器
    • STRING
    • float
    • int
    number_type
    mode
    start0.00
    stop0.00
    step1.00
    reset_bool

    ComfyUI has no native "number that ticks up each time I run this" - and that's a real hole. People fake it with seeds, renumber files by hand, or bolt on Python hacks. hb_Number_Counter (display name "计数器") from the 1H-hobit/ComfyUI_InternVL3 pack is the simple version: a counter that increments every time the graph runs and remembers its value between runs, so you can label saved images 001, 002, 003 without ever touching the filename widget again.

    How it works

    Each copy of the node keeps its own state, keyed by its node id, held in memory. Because the node declares IS_CHANGED as always-changed, it executes on every queue run - that's what makes it a counter and not a "sets itself once and freezes" node. Restart ComfyUI and it resets to start; copy the node and the copy starts fresh. Nothing persists to disk, which is usually what you want for batch naming.

    Pick a behavior with mode:

    • increment / decrement - tick up or down by step forever.
    • increment_to_restart - count up until stop, then snap back to start. Same idea backwards with decrement_to_restart. This is your loop counter for workflows that should run a bounded number of passes before recycling.

    The inputs that matter

    • number_type - integer or float. Controls how the value is formatted on the outputs.
    • start, stop, step - all floats. step defaults to 1; there's no reason to set it below 0.
    • reset_bool - optional numeric input. Feed it a value ≥ 1 and the counter snaps back to start. Wire a boolean toggle or a threshold check in here for "restart the count now" control from inside the graph.

    Outputs

    The same value, three ways, so you can grab whichever type a downstream node wants: STRING, float, and int. The detail that makes it worth reaching for: in integer mode the string is zero-padded to three digits - 001, 002, 042. That's exactly what you want when building a filename so image viewers sort them correctly. Feed the STRING output into a save-image node's filename template and batch output numbering just works.

    Install

    It ships inside the InternVL3 pack, which is mostly about running InternVL vision-language models - but this node has nothing to do with any of that. Manager → search ComfyUI_InternVL3, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/1H-hobit/ComfyUI_InternVL3.git
    

    Restart ComfyUI. The repo has no requirements.txt, so nothing installs automatically, and this node needs nothing beyond core ComfyUI anyway - no model download, no HuggingFace account, no GPU strain. You can use it even if you never load a single InternVL model.

    Where people get tripped up

    The obvious one: the counter bumps on every graph execution, not once per image in a batch. If your workflow batches 4 images, a single run ticks the counter 4 times, so 001 becomes 004 before you've even looked at the first output. If you need one tick per run regardless of batch size, put it after a node that executes once, or accept the behavior and plan for it. Also keep the memory-only state in mind: it's not a "set this to 7" constant - it's genuinely a running tally, and a workflow that re-executes for unrelated reasons (you tweaked a prompt and reran) keeps counting. For filename sequencing it's the right tool; for anything that needs deterministic state, it isn't.

    Categoryinternvl

    Inputs (6)

    NameTypeDefaultDescription
    number_typeCOMBO2 options: integer, float
    modeCOMBO4 options: increment, decrement, increment_to_restart, decrement_to_restart
    startFLOAT0.00-18446744073709550000–18446744073709550000
    stopFLOAT0.00-18446744073709550000–18446744073709550000
    stepFLOAT1.000–99999
    reset_booloptNUMBER

    Outputs (3)

    NameTypeDescription
    STRINGSTRING
    floatFLOAT
    intINT