Latent Switch
Route two latent streams without the decode-encode round trip
- Latent_1
- Latent_2
- Latent
- Selection
Latent Switch does for LATENT tensors what Image Switch does for pixels - two in, one out, chosen by a 1-or-2 selection. It sounds trivial, but it unlocks a genuinely nice pattern: toggling between two latents without decoding to pixels and re-encoding, which is a lossy round trip you don't want to pay.
Why switching latents is the smart move
In ComfyUI, a LATENT is the compressed representation the diffusion model actually works in - roughly an eighth of your target resolution, four channels deep (or sixteen on newer architectures). Every decode-to-image and re-encode-to-latent cycle loses a little detail. So when you want to choose between two generation paths - say, a fresh txt2img latent versus an img2img latent from a source image, or two different noise seeds - switching at the latent level means you pick a stream and keep sampling it directly, with no pixel detour.
It also plays well with the common "one workflow, two generation modes" setup: generate straight, then flip Selection to feed an img2img source instead. Because the selection is an INT, you can wire it to a Logic Compare or a random seed and let the graph decide which latent path runs.
How it works
Standard switch family mechanics:
case 1: return (Latent_1, Selection,)
case 2: return (Latent_2, Selection,)
Inputs:
- Selection - 1 or 2, an INT you can drive from any integer source.
- Latent_1 and Latent_2 - LATENT dicts from an Empty Latent node, a VAE encode, or a previous KSampler's output.
Outputs:
- Latent - the selected latent, straight into a KSampler, a latent upscaler, or a VAE decode.
- Selection - echoed through, so downstream nodes can react to which path won.
Where people get burned
Latent_2 is optional - the classic trap of this whole switch family. Leave it unwired, flip to 2, and you feed a None into your sampler, which usually dies with an unhelpful "Expected LATENT" style error. Wire both branches.
Also remember the switch-selects-not-skips rule: ComfyUI still executes whatever feeds both inputs, so the unselected latent branch gets computed each run anyway. If you're switching to avoid computing a branch, mute it instead.
One thing to watch: latent dimensions must be compatible with whatever the sampler expects. The switch doesn't check that Latent_1 and Latent_2 are the same resolution - if you flip between a 512×512 and a 1024×1024 latent, the sampler downstream may or may not cope depending on what it is. Keep your two branches dimensionally aligned.
Installing it
ComfyUI Manager → search "HavocsCall" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/HavocsCall/comfyui_HavocsCall_Custom_Nodes
Restart, and it's under HavocsCall/Switches. No requirements.txt, no downloads, nothing extra to install - the pack only uses libraries ComfyUI already ships.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| Selection | INT | 11–2 | — |
| Latent_1 | LATENT | — | |
| Latent_2opt | LATENT | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| Latent | LATENT | — |
| Selection | INT | — |