ComfyUI Node

[Book Tools] Loop

The pack's loop engine — a global counter dressed up as a node

By Big-Idea-Technology·Created 2 years ago·Updated 8 months ago· 40
[Book Tools] Loop
    • LOOP
    • Iteration
    resetfalse

    BTLoop is the engine of the Book Tools loop system - the node that actually loops. It's the author's rework of the well-known ComfyUI loopback nodes (the author credits the Civitai "ComfyUI-Loopback-Nodes" as the basis, with two upgrades: it passes any type through, and it gained a reset switch). If you've seen those older loop nodes, you'll feel right at home; if you haven't, think of it as a counter that makes ComfyUI re-run your graph with a new value each pass.

    What it outputs

    Two outputs, and they're the whole point:

    • LOOP - the loop object itself. You thread this single wire into BTLoopStart and BTLoopEnd to close the cycle.
    • Iteration - an INT that counts the current pass (1, 2, 3…). Wire it anywhere you'd want a changing number per page: a BTPromptSelector index, a seed offset, a text-growth target.

    The only input is reset (BOOLEAN, default false). Flip it to true and the counter snaps back to 1.

    How the loop actually turns

    Read the source and the honesty shows up immediately: the counter is a module-level global, not state on the node. IS_CHANGED increments it every time ComfyUI re-evaluates the node, and because the counter changed, ComfyUI re-executes everything downstream. That's the trick - a loop in ComfyUI isn't a real for loop, it's "change a global number, get the graph to run again." BTLoopStart then decides whether to feed the initial value or the previous pass's result, and BTLoopEnd hands that result back.

    So the shape you build is:

    BTLoop ──LOOP──► BTLoopStart ──► [body: generate, overlay, whatever] ──► BTLoopEnd
      ▲                                                      │
      └────────────────────── same LOOP wire ◄───────────────┘
    

    The LOOP wire is one shared object; it must flow through both Start and End, or the feedback never connects.

    What to know before you commit to it

    This pattern works, but it has real limits, and they come straight from the code:

    • Iteration is global. There's one module-level counter, so two independent loops in the same workflow share it and stomp on each other. One loop per workflow is the safe bet.
    • Each pass is a fresh queue execution. Everything in the loop body re-runs from scratch, including model loads, so a loop body with a checkpoint load is slow.
    • The count increments on evaluation, not on queue runs. If ComfyUI caches and skips a pass, the number and the actual render can drift - keep the loop body's inputs changing each pass so it doesn't get cached.

    Installing

    The pack installs light - no models, no extra pip deps beyond what ComfyUI ships:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Big-Idea-Technology/ComfyUI-Book-Tools
    # restart ComfyUI
    

    Or via ComfyUI Manager: search "ComfyUI-Book-Tools".

    For a book workflow, BTLoop driving BTPromptSelector (one prompt per page) with BTImageTextOverlay stamping text is the canonical setup - set reset to true when you want to restart the batch from page one.

    Categoryloopback

    Inputs (1)

    NameTypeDefaultDescription
    resetBOOLEANfalse

    Outputs (2)

    NameTypeDescription
    LOOPLOOP
    IterationINT