Nodes/Comfyui_TextBatch_aidec/Universal Loop Controller
ComfyUI Node

Universal Loop Controller

Universal Loop Controller (UniversalLoopController) — ComfyUI Node

By aidec·Created 2 years ago·Updated 9 months ago· 19
Universal Loop Controller
  • 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
loop_count3
accumulate_modenone
trigger_nexttrue
reset_on_starttrue

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 none unless you actually want every iteration's output gathered up; image in 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_1input_5 slots (any type) that pass straight through to output_1output_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.

CategoryTextBatch

Inputs (9)

NameTypeDefaultDescription
loop_countINT31–1000
accumulate_modeCOMBOnone4 options: none, text, image, any
trigger_nextBOOLEANtrue
reset_on_startBOOLEANtrue
input_1opt*
input_2opt*
input_3opt*
input_4opt*
input_5opt*

Outputs (10)

NameTypeDescription
current_loopINT
total_loopsINT
completedBOOLEAN
output_1*
output_2*
output_3*
output_4*
output_5*
accumulated_results*
statusSTRING