Nodes/Painting Coder Utils/Latent Switch 🔄
ComfyUI Node

Latent Switch 🔄

The lazy way to flip between two sampling paths without rebuilding the graph

By jammyfu·Created 2 years ago·Updated 2 years ago· 16
Latent Switch 🔄
  • latent_1
  • latent_2
  • latent
use_firsttrue

Sometimes you want to compare two paths in the same graph - the output of a first KSampler vs. a second pass, an img2img latent vs. a fresh text-to-image one - and you don't want to rewire three connections every time. Latent Switch is the two-position rail switch for that. A single boolean flips which latent flows downstream.

It's one of four tiny switch nodes in the Painting Coder Utils pack (ImageSwitch, TextSwitch, and MaskSwitch are its siblings). They're deliberately dumb: no conditionals beyond a boolean, no fancy routing. That's the appeal - set the toggle, run, done.

How it works

The node has two optional latent inputs and one boolean, use_first. When use_first is checked it passes latent_1 through; uncheck it and latent_2 wins. Nothing is transformed, no sampling happens - it's a wire with a switch.

Two behaviors worth knowing before you use it:

  • If you pick a path that has nothing connected, it returns an empty latent (torch.zeros shaped like a 1024×1024 SDXL latent) instead of erroring. That keeps the workflow running but means a KSampler downstream will happily sample black noise. A blank latent is not a "skip this path" signal - it's an actual black image waiting to happen.
  • The node is also registered to not invalidate its own cache, so it won't force a re-run of the whole graph by itself. Queue explicitly if you flip the switch and expect changes to show up.

The inputs that matter

  • use_first - the boolean switch. true = latent_1, false = latent_2.
  • latent_1, latent_2 - the two LATENT inputs. Both are optional; connect whatever you're switching between.
  • Output: latent - whatever you picked, wired straight into a KSampler, VAE decode, or latent math node.

Where you'll reach for it

The classic use is an A/B test rig: two KSamplers with different seeds or samplers feeding into one Latent Switch, so you can compare generations without editing the graph. Or a fallback pattern - a fully-sampled latent on one side, an untouched latent on the other, and the switch decides which version continues the workflow.

Honest take: if you already run rgthree or similar utility packs, you have a more capable Switch node that also handles images and text from one interface, and you may not need these. But if you want a dependency-light, dead-simple switch that does exactly one thing, this works and needs nothing else installed.

Install

Grab it via ComfyUI Manager (search Painting Coder Utils) or:

cd ComfyUI/custom_nodes
git clone https://github.com/jammyfu/ComfyUI_PaintingCoderUtils.git

Restart ComfyUI after cloning. No model files, no API keys - the pack's dependencies (numpy, Pillow, torch, gradio) are already present in any working ComfyUI. One gotcha if you're inheriting old workflows: the pack renamed its namespace in v0.3.0, so pre-update JSON may reference old class names. The included fixer tool at docs/fix/workflow_fixer.html repairs those files.

Category🎨Painting👓Coder/🔄Switch

Inputs (3)

NameTypeDefaultDescription
use_firstBOOLEANtrue
latent_1optLATENT
latent_2optLATENT

Outputs (1)

NameTypeDescription
latentLATENT