ZML_下游节点开关
Let a node's downstream run only every Nth execution
- 任意输入
- 任意输出
- 当前计数
Some jobs you only want done every so often. You batch-generate 20 images and want to save only every 5th one, or run a heavy upscaler only on the last pass of a loop, or trigger a notification every 10th render instead of every render. This node is a gate: you set a 计数 (count), and whatever flows through it only reaches the downstream nodes on the Nth execution; the other N−1 runs get blocked dead.
How it works
It exploits ComfyUI's execution machinery directly. The node is marked OUTPUT_NODE = True and imports ExecutionBlocker from comfy_execution.graph - the engine's own mechanism for suppressing work downstream of an output. A class-level counter increments on every execution; when the counter hits your count, the input value passes through and the counter resets to zero. On non-matching runs it returns an ExecutionBlocker(None), which tells the engine to skip everything downstream.
Two details worth knowing before you rely on it:
- The counter is class-level, so it's shared across every copy of this node in your graph - and it lives for the ComfyUI process. Restart ComfyUI and it resets. If you have two of these in one workflow, they share state; that's usually a surprise, not a feature.
- 计数 = 0 always passes everything through, so 0 is effectively "off."
The inputs
- 任意输入 - any type; whatever you want gated. The node is type-agnostic (
*). - 计数 - 1–10. Count = how many executions before downstream runs once.
Outputs: 任意输出 (the value, on pass-through runs) and 当前计数 (the running counter value, so you can wire it into a text block or debug node to see where you are in the cycle).
Installing
Standard pack install:
cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image
restart, or ComfyUI Manager. The English translation patch (https://github.com/zml-w/ZZZ_ZML_English_Patch) will make the labels legible. No extra dependencies.
Common issues
The shared class-level counter is the trap - put two of these in a workflow and they interfere with each other because they're the same counter underneath. If you need independent gating, use one node per gate and don't expect isolation. Also, because it's an output node with a blocking value, anything that feeds into it still runs every time (it has to, to know whether to block) - this gates the downstream of the node, not upstream. And remember it's process-lifetime state: a long ComfyUI session with a half-finished cycle can look like the node "randomly" started passing or blocking. Reset the count (or restart) to get a clean cycle. For "save every Nth render" this is the cleanest little gate in the pack.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| 任意输入 | * | — | |
| 计数 | INT | 11–10 | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| 任意输出 | * | — |
| 当前计数 | INT | — |