Nodes/ComfyUI-ZML-Image/ZML_切换输出
ComfyUI Node

ZML_切换输出

The any-type A/B switch that prunes the dead branch

By zml-w·Created about a year ago·Updated 2 months ago· 218
ZML_切换输出
  • 输入
  • 输出1
  • 输出2
选择输出false

A switch node is the most requested piece of plumbing in ComfyUI, and every pack ships one. ZML_SwitchOutput is this pack's A/B version: one input of any type, one boolean toggle, two outputs, and the input goes to whichever output you've selected. What makes it slightly unusual is what happens to the branch you didn't pick - for non-primitive types it doesn't just sit there unused, it gets blocked from executing, so the dead branch's entire downstream graph is skipped.

The input socket is wildcard-typed (*), which is the ComfyUI escape hatch for "any type will do" - wire in a model, a latent, an image, a conditioning, anything. The node doesn't care, it just routes.

The inputs and outputs

  • 输入 (required, any type) - the value to route.
  • 选择输出 (required, boolean) - the switch. The widget labels itself: 输出1 (off) and 输出2 (on).
  • 输出1 / 输出2 (both any type) - the two possible destinations. The active one carries your input; the inactive one carries whatever the placeholder behavior gives it.

How the placeholder behavior works

This is the detail worth understanding, and it's a deliberate design choice the author documented in the code: for integers and strings, the unselected output returns an empty value (0 for ints, "" for strings) instead of blocking. Why? Because downstream text and integer nodes handle a harmless empty value better than they handle a blocked execution - you can chain text nodes off both outputs without the unselected one erroring out.

For everything else - images, models, latents, conditioning - the unselected output returns an ExecutionBlocker, which makes ComfyUI skip that whole downstream branch. So if you switch between two image pipelines, only the live one does any work. This is the same mechanism the pack's TextCondition uses, and it's genuinely useful: switching a heavy branch off isn't just cosmetic, it saves you the compute.

Where it fits

The classic pattern: two LoRA/checkpoint setups in one workflow, flip the toggle to pick which one generates. Or a save-vs-preview fork - send the image to a SaveImage on output1, a PreviewImage on output2, and switch without rewiring. Because the toggle is a plain boolean, an upstream logic node can flip it, which turns this into an automated router rather than a manual one.

Honest note: if you only need to pick the first non-empty input (fallback logic), you want a first-non-null switch like rgthree's Any Switch instead - this node is a selector, not a fallback, and they solve different problems. And if you need more than two destinations, the pack's ZML_SwitchOutputFive is this same node with five outputs and an index.

Install

ComfyUI Manager → search "ComfyUI-ZML-Image", or cd ComfyUI/custom_nodes && git clone https://github.com/zml-w/ComfyUI-ZML-Image, restart. Displayed as ZML_切换输出 in the Chinese-default UI; the English patch covers it. No models or extra dependencies.

Categoryimage/ZML_图像/逻辑

Inputs (2)

NameTypeDefaultDescription
输入*
选择输出BOOLEANfalse

Outputs (2)

NameTypeDescription
输出1*
输出2*