Nodes/ComfyUI-ZML-Image/ZML_任意切换
ComfyUI Node

ZML_任意切换

A switch that routes anything — models, latents, whatever

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

The name is a lie in the best way - it doesn't switch anything by type. ZML_AnyTypeSwitch (ZML_任意切换) switches anything. Two inputs, one boolean, one output: flip the boolean and the node passes whichever input you pointed at, no matter whether those inputs are images, models, latents, or strings. It's the A/B routing valve from the pack's logic section, and it's the answer to "how do I keep two model loaders in one workflow and flip between them without re-wiring."

What it is

This is the classic any-type (wildcard *) switch, the same family as rgthree's Any Switch and the ones in ComfyUI-Easy-Use - which is no coincidence: the README credits Easy-Use's switch as the inspiration. The whole trick works because ComfyUI's type system has one escape hatch: a socket typed * accepts a connection from anything, and it's "up to the node to make sense of the data." A switch doesn't need to make sense of anything - it just hands one object to the next node. That's the engine fact that makes all of this work, and it's covered properly in the node-plumbing layer.

The inputs that matter:

  • 判断 (BOOLEAN, default false) - the selector. In the UI it renders as a toggle labeled "choose input 1" / "choose input 2", so you don't have to remember which side is which.
  • 输入值1 / 输入值2 (any type, optional) - the two candidates. Leave one unwired and it's simply not passed; the node only asks for the one the boolean points at.

Output is 选择的输出 (any type), which wires straight into whatever needs the value.

The lazy part, and why you should care

Where this node is smarter than a naive "pass input A" is check_lazy_status. ComfyUI supports lazy evaluation - a node can declare which inputs it actually needs and the engine skips computing the rest. This switch tells ComfyUI to only execute the upstream branch it selected. So if input 1 comes from an expensive sampler and input 2 from a cheap one, flipping the boolean means the expensive branch doesn't run at all. That's the difference between a router that works and a router that secretly generates a second image you didn't ask for.

Install and gotchas

Same as the whole pack:

cd ComfyUI/custom_nodes
git clone https://github.com/zml-w/ComfyUI-ZML-Image

or ComfyUI Manager → ComfyUI-ZML-Image, restart. Nothing else to install for this node.

The honest take: this is a clean, well-behaved A/B switch, but it's also the most crowded category in ComfyUI - rgthree, Easy-Use, and a dozen others all ship one. Where ZML's version stands out is the lazy evaluation and the fact that it's already in your custom_nodes directory if you installed this pack for anything else. One caveat from the pack's author himself: this is a one-person project where some nodes are polished and some are "works for me," so if a switch misbehaves, that's a GitHub issue, not a community forum - this pack has essentially no English-speaking Reddit presence. Also, if you just want "first connected input wins" without a selector, that's a fallback switch (rgthree's Any Switch), and this isn't it - this one always needs the boolean told which way to go.

Categoryimage/ZML_图像/逻辑

Inputs (3)

NameTypeDefaultDescription
判断BOOLEANfalse
输入值1opt*
输入值2opt*

Outputs (1)

NameTypeDescription
选择的输出*