Nodes/Boyonodes/Boyo Latent Switch
ComfyUI Node

Boyo Latent Switch

The clean way to feed last iteration's latent back into a looped sampler

By DragonDiffusionbyBoyo·Created 2 years ago·Updated 26 days ago· 16
Boyo Latent Switch
  • start_latent
  • next_latent
  • latent
counter0
cache_keylatent_loop_cache

Looped video generation has a first-iteration problem. On pass zero you have no previous chunk, so you start from an empty latent or an init image. On every pass after that, you want to start from the latent the last pass produced. Boyo Latent Switch exists to draw that line: it outputs start_latent on iteration 0 and the cached latent from the previous iteration on everything after. It's the read-half of the pair that makes chunked video loops legal without a graph cycle.

The counter input is what decides. Hook it to your loop counter, and the node does the rest: first pass uses and caches the start latent; later passes pull from the cache via the shared cache_key. If the cache is somehow empty it falls back to the start latent rather than crashing - a nice touch when you're debugging a loop from a cold start.

The inputs

  • counter - the loop iteration. 0 means first pass; anything higher means "fetch from cache."
  • start_latent - used on iteration 0. Usually an empty latent or a first-frame init.
  • cache_key - must match the key on Boyo Latent Cache Updater (default latent_loop_cache both sides).
  • next_latent - optional. If provided, the node updates the cache for the following iteration right here instead of relying on a separate Cache Updater node.

Output: latent, wired into your sampler's latent input.

Install

Part of Boyonodes. ComfyUI Manager → search "Boyonodes", or:

cd ComfyUI/custom_nodes
git clone https://github.com/DragonDiffusionbyBoyo/Boyonodes

Restart. No extra dependencies.

The pair, wired together

Two clean arrangements exist. Simplest: Latent Switch → sampler → Latent Cache Updater → decode, with the switch's next_latent fed from the sampler so it pre-caches. Or keep them strictly separate - updater after the sampler writes the cache, switch before the sampler reads it. Either way the golden rule is the same cache_key on both nodes. Miss that, and you'll get iteration 0's latent on every pass, which presents as "my loop isn't actually looping." That's the first thing to check.

CategoryBoyo/Latent

Inputs (4)

NameTypeDefaultDescription
counterINT00–999999
start_latentLATENT
cache_keySTRINGlatent_loop_cache
next_latentoptLATENT

Outputs (1)

NameTypeDescription
latentLATENT