Nodes/ComfyUI_MieNodes/Mie Loop Body Out ๐Ÿ‘
ComfyUI Node

Mie Loop Body Out ๐Ÿ‘

Close the loop body and carry state between iterations

By MieMieeeeeยทCreated 2 years agoยทUpdated 27 days agoยท 225
Mie Loop Body Out ๐Ÿ‘
  • loop_ctx
  • loop_ctx
  • state_json
โ—„state_json{}โ–บ

If MieLoopBodyIn marks where a loop pass begins, MieLoopBodyOut marks where it ends. It closes the body of MieNodes' loop system and, crucially, gives you a slot to carry accumulated state from one iteration into the next.

It's part of ComfyUI-MieNodes (ComfyUI_MieNodes), MieMieeeee's utility pack, under ๐Ÿ‘ Loop.

Why you'd reach for it

A loop that can't remember anything between iterations is just a repeated action. The useful loops accumulate: build a running list, keep a counter, tally results, append each pass's output to a growing record. To do that you need somewhere to stash state that survives the trip back to the top of the loop. That's what this node's state_json gives you - a string of JSON that rides along with the loop context and is available on the next pass.

JSON is a smart choice for it: it's a plain string, so it threads through the graph easily, and it can hold structured data - a list, an object, nested values - without needing a bespoke type for every shape of state you might want to keep.

How it works

MieLoopBodyOut takes the loop context (threaded down from MieLoopBodyIn through your per-iteration work) and hands it back out, signalling the end of the body. Alongside it, the optional state_json input (default "{}", an empty object) lets you pass in the state you've built up this iteration; it comes back out the state_json output so the loop can feed it forward. Read it at the top of the next pass, update it, pass it back in here - that's the accumulation cycle.

The inputs and outputs that matter

  • loop_ctx (MIE_LOOP_CTX, required) - the context, arriving from the body. Passing it through here is what closes the pass.
  • state_json (STRING, optional, default "{}") - your carried-over state as JSON. Leave it at {} if the loop doesn't need memory.
  • loop_ctx (output) - threaded onward to finish the iteration.
  • state_json (output) - the state, back out for the next pass or for reading after the loop ends.

Installing it

ComfyUI Manager โ†’ search ComfyUI-MieNodes โ†’ install โ†’ restart. Or:

cd ComfyUI/custom_nodes
git clone https://github.com/MieMieeeee/ComfyUI-MieNodes

then restart. No model download. Nodes appear under ๐Ÿ‘ MieNodes.

Common issues & troubleshooting

Malformed JSON breaks the state. state_json has to stay valid JSON. If you're building the string by hand, one missing quote or trailing comma will trip whatever parses it on the next pass. Build it with a proper serialize step rather than string-concatenating by hand, and start from the {} default.

State resets every iteration. If your accumulated value keeps coming back empty, the feed-forward wiring is broken - the state_json output has to actually route back to where the next pass reads it. A loop that reads a fresh {} each time isn't threading its own state.

You must pair it with the In node. MieLoopBodyOut only makes sense as the closing bracket to MieLoopBodyIn; the MIE_LOOP_CTX has to flow in at the top and out at the bottom for the pass to be well-formed. Since the pack documents this subsystem lightly, build it incrementally and verify each pass runs before adding accumulation on top.

Category๐Ÿ‘ MieNodes/๐Ÿ‘ Loop

Inputs (2)

NameTypeDefaultDescription
loop_ctxMIE_LOOP_CTXโ€”
state_jsonoptSTRING{}โ€”

Outputs (2)

NameTypeDescription
loop_ctxMIE_LOOP_CTXโ€”
state_jsonSTRINGโ€”