Universal Loop Controller
Universal Loop Controller (UniversalLoopController) — ComfyUI Node
- input_1
- input_2
- input_3
- input_4
- input_5
- current_loop
- total_loops
- completed
- output_1
- output_2
- output_3
- output_4
- output_5
- accumulated_results
- status
Universal Loop Controller is a for-loop for ComfyUI. Set it to run your workflow N times, and it re-queues itself, counting up, until it's done - handing the rest of the graph the current iteration number each pass so something can be different every time. If you've ever wanted "generate 20 images, each with a different prompt or seed or setting" without babysitting the queue button, this is the category of node you're after.
Worth saying up front: ComfyUI doesn't loop on its own. The graph engine gained the capability a while back, but there are no loop nodes in the default install - you pull them from third parties. The canonical one is BadCafeCode's execution-inversion demo; others, like WWAA's nested-loop nodes and this one, are community takes on the same idea. So UniversalLoopController isn't doing anything exotic. It's aidec's flavor of a well-worn pattern, tuned for the text-batch workflow the rest of the pack is built around.
How it works
It's an output node - the thing that anchors execution - so it fires on each queue, checks whether it's hit loop_count, and if not, triggers the next run with the counter bumped by one. trigger_next is the switch that makes that auto-requeue happen; turn it off and it just reports the count without advancing. reset_on_start zeroes the counter when you kick off a fresh run, so you're not resuming from wherever the last batch left off. accumulate_mode (none / text / image / any) decides whether each pass's result gets collected into one growing list you can grab at the end.
The inputs that matter:
- loop_count - how many times to run, 1 to 1000.
- accumulate_mode - leave it on
noneunless you actually want every iteration's output gathered up;imagein particular piles results in memory. - reset_on_start and trigger_next - leave both on for normal "run the whole batch now" behavior.
There are also five optional input_1–input_5 slots (any type) that pass straight through to output_1–output_5, so you can route values around the loop body without a mess of reroutes.
The output you'll wire most is current_loop - the iteration index. Send it into a Text Split Get's index and you've built the standard batch-prompt loop: the controller counts 0, 1, 2…, TextSplitGet pulls the matching line, the sampler renders it, repeat. total_loops mirrors your count, completed flips to true on the final pass (gate a "save the whole set" step on it), accumulated_results is the collected list when accumulation's on, and status is a readable progress string.
Installing it
Same one-liner as the rest of the pack - no models, no heavy dependencies:
cd ComfyUI/custom_nodes
git clone https://github.com/aidec/Comfyui_TextBatch_aidec.git
Or search Comfyui_TextBatch_aidec in ComfyUI Manager, then restart.
Common issues
Here's the honest part, because loop nodes in ComfyUI are finicky and this pack is no exception - the author says as much himself. Two warnings from the README are worth repeating. First, the opening run sometimes only executes a single iteration; let it finish, run it again, and it behaves. Second, don't have several ComfyUI tabs or workflows open at once while it's looping - queuing from a second window, or stacking queues, can throw it off. The auto-requeue trick these nodes lean on is genuinely fragile; if you find yourself fighting it constantly, BadCafeCode's execution-inversion loops are the more robust route.
Watch accumulate_mode, too. Accumulating images across a long loop holds them all in memory at once - which is exactly the kind of memory blowup the pack's own image nodes were later rewritten to avoid, so don't casually set it to image on a 200-iteration run. And keep the node in perspective: this is a small, solo-maintained pack (aidec, blog.aidec.tw), and any custom node runs unsandboxed Python. Treat it as a handy specialist for a batch job - not core infrastructure to build a fragile tower on.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| loop_count | INT | 31–1000 | — |
| accumulate_mode | COMBO | none | 4 options: none, text, image, any |
| trigger_next | BOOLEAN | true | — |
| reset_on_start | BOOLEAN | true | — |
| input_1opt | * | — | |
| input_2opt | * | — | |
| input_3opt | * | — | |
| input_4opt | * | — | |
| input_5opt | * | — |
Outputs (10)
| Name | Type | Description |
|---|---|---|
| current_loop | INT | — |
| total_loops | INT | — |
| completed | BOOLEAN | — |
| output_1 | * | — |
| output_2 | * | — |
| output_3 | * | — |
| output_4 | * | — |
| output_5 | * | — |
| accumulated_results | * | — |
| status | STRING | — |