Nodes/yanhuo-easy-use/整数控制
ComfyUI Node

整数控制

A number box that steps itself — and the \"after\" trap it inherits

By yanhuoxunxianren·Created 27 days ago·Updated 21 days ago· 2
整数控制
    • 整数
    ◄数值0►
    ◄生成后控制固定►
    ◄增加数值0►
    ◄减少数值0►

    Every integer widget in ComfyUI - the seed on a KSampler being the one you meet first - carries a hidden second widget called control_after_generate that decides what happens to the number after a run. 整数控制 (YanhuoIntegerControl) is a standalone version of that idea: a number you can hold fixed, step up, step down, or randomize, with the step sizes under your control instead of hardwired to ±1.

    Why a separate node for this

    Two reasons, both about fan-out and order.

    One value, several consumers. Wire one Integer Control output to five nodes that used to each have their own typed-in number, and you only edit it in one place. That's the standard primitive-node argument: a value broken out of a widget becomes a thing the graph can share.

    Steps bigger than one. control_after_generate gives you ±1, so a workflow that walks a shot list or an index into a folder of reference images has to be re-typed by hand each run. Here 增加数值 and 减少数值 are full integer fields, so you can advance by 12, by 250, by whatever your batch stride is.

    The mechanism, and the word "after"

    Three of the four modes are the interesting part:

    • 固定 - returns 数值 and changes nothing.
    • 增加 - returns 数值 as the current run's output, and writes 数值 + 增加数值 back into the widget for the next run.
    • 减少 - same, subtracting.
    • 随机 - ignores the box and returns a fresh roll across the full 64-bit integer range.

    Read 增加 again carefully, because this is the trap the whole feature inherits from core ComfyUI: the number in the box is the one you'll use next, not the one that just ran. Find a great seed, flip the mode to 固定 to keep it, and you may have already lost it - the good value was overwritten at the end of the run. The community complaint about this on core nodes is unusually crisp and years old: people lose a seed they liked by switching to fixed after the run instead of before. The global fix for core is a setting ("widget control mode") that makes the control fire before the run instead of after. That setting is core-level, and this node bakes the after-semantics in as its documented behaviour, so treat it as "the next value is displayed."

    The output port is a single 整数 INT. Nothing else - feed it to a seed input (converted from a widget to a socket), to an index, to a filename token, or to another arithmetic node.

    Two implementation quirks worth having in your head when a workflow behaves oddly:

    It always re-runs. The node's cache key is NaN, the idiom that makes ComfyUI's cache comparison always unequal because NaN isn't equal to itself. That's exactly right for a counter - it must fire each run - and it has a known cost: a node pinned this way defeats the cache for everything behind it in that branch. If a graph feels slower than it should, an always-dirty node is a prime suspect, and this is one.

    The random roll is genuinely random. It's a uniform integer across the int64 range, not the friendly small number people expect from seed randomizers. If you're using it as a seed, that's fine; if you're plugging it somewhere that expects a small positive index, it isn't.

    The four required inputs are exactly what they look like - 数值, the 生成后控制 dropdown, and the two step fields, all of which only matter in their matching mode. The UI hides whichever step field your current mode doesn't use, which keeps the node tidy.

    Install

    Part of yanhuo-easy-use (16 nodes, category yanhuo, Chinese UI labels, MIT, v1.3.1). ComfyUI Manager → search the pack title → install → restart. Manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/yanhuoxunxianren/yanhuo-easy-use
    # restart ComfyUI
    

    No pip install (empty dependency list in pyproject.toml) and no model files. Note that the write-back of the next value into the widget is done by the pack's own frontend extension, so if the node is on the canvas but the number never advances, suspect the frontend loaded an old file - hard-refresh the browser tab after install.

    Common issues

    "The number never changes between runs." The frontend extension that applies the new value didn't load, or the graph was loaded from a workflow saved before the pack updated. Hard-refresh; check the browser console for extension errors.

    "My seed changed and I didn't ask it to." You left the mode on 增加/减少/随机. The write-back happens at the end of the run, so the visible value after a queue is the next one.

    "The whole branch re-runs every single queue." Expected - IS_CHANGED returns NaN on purpose. If that branch is expensive, put the control outside it, or accept the cost of keeping the value authoritative.

    "My graph got slower after I added it." Same cause. It's the price of a counter that always ticks; a workflow that felt snappier before this node went in has found its culprit.

    "Can I use it for a float?" No - the ports are INT only, matching the name. For floats, convert or use a float primitive.

    The control_after_generate semantics, the Before/After setting, the NaN cache idiom and its cost are all laid out in docs/knowledge/comfyui-node-plumbing.md, which is the one page to read if this node's behaviour is confusing you.

    Categoryyanhuo

    Inputs (4)

    NameTypeDefaultDescription
    数值INT0-9223372036854776000–9223372036854776000—
    生成后控制COMBO固定4 options: 固定, 增加, 减少, 随机
    增加数值INT0-9223372036854776000–9223372036854776000—
    减少数值INT0-9223372036854776000–9223372036854776000—

    Outputs (1)

    NameTypeDescription
    整数INT—