Nodes/ComfyUI-QG-tools/任意切换
ComfyUI Node

任意切换

Let the graph pick the input, not you

By live1617·Created 9 days ago·Updated a day ago· 1
任意切换
  • any_01
  • any_02
  • any_03
  • any_04
  • any_05
  • any_06
  • any_07
  • any_08
  • any_09
  • any_10
  • any_11
  • any_12
  • any_13
  • any_14
  • any_15
  • any_16
  • any

The first time you build a workflow with an optional branch - a high-res model you only have sometimes, an upscaler you only want on finals - you hit a wall: the sampler has one model input slot, and you have two candidates for it. Most people solve that by deleting one wire and re-dragging the other. The switch nodes exist so you don't.

任意切换 (QG_AnySwitch, filed under QG-tools/逻辑) is the fallback shape of a switch. There's no selector widget, no A/B toggle. You wire things in, and the node walks its inputs in order and outputs the first one that is actually connected and non-empty. The graph decides, not you.

Why this shape and not an A/B switch

The KB's map of the plumbing layer splits switches into two families: the A/B switch with a selector you flip, and the first-non-null fallback. An A/B switch is a manual valve - you keep two loaders on one canvas and toggle between them. A fallback is closer to a or b or c in code. You use it when the answer shouldn't require your input: if the face-detail model is loaded, use it; if it isn't, quietly run without it.

That's the whole trick, and it's why the node collapses a surprising amount of "which workflow version should I run today" thinking into one wire.

How it works

Sixteen optional sockets, named any_01 through any_16, all typed as ComfyUI's wildcard *. You connect as many as you want, at least two for it to be useful; the frontend grows and shrinks the socket list as you wire. Middle slots keep their position, so priority is stable and unplugging slot 3 doesn't promote slot 7 into its place.

The output is a single any socket, and it's the first non-empty value found, scanning in index order. "Empty" is broader than "not connected" - the source treats a None, an execution blocker, an empty string, an empty list/dict, and a zero-element tensor as empty. So a muted upstream branch that passes an empty placeholder falls through to the next input instead of poisoning the sampler.

Two things it deliberately refuses to do:

  • Mix types. If you wire an IMAGE into one slot and a LATENT into another, you get a RuntimeError naming both types instead of a mis-typed tensor halfway down the graph.
  • Pass None. If everything is unconnected or empty, it raises rather than handing downstream a null it can't explain. Ugly on purpose: the failure lands where the mistake is.

Want the messy-latent check to still be caught upstream? The type comparison buckets tensors by rank - 4-D counts as image, a dict with samples counts as latent - so it's checking shapes, not just Python classes.

Inputs and outputs

The only thing you set is what you plug in. any_01 … any_16 are all optional wildcards; ordering is priority. any is the output, and its socket label follows whatever type you actually connected, so it reads "图像" once an image is wired.

Wire any into whatever the branch was feeding: a sampler's model, a VAE decode's samples, a ControlNet's image. Because the node is type-erased, connecting it to a typed input is on you - the frontend can't warn you the way it would with a plain IMAGE socket.

Install

Manager search for ComfyUI-QG-Tools works once the pack is on the Comfy Registry; until then, clone it:

cd ComfyUI/custom_nodes
git clone https://github.com/live1617/ComfyUI-QG-tools

Restart ComfyUI fully (not a browser refresh in place of one). The console should print [QG-tools] v0.9.2 加载完成 | 节点数 24. There's nothing to pip install - the requirements file is deliberately comments-only so Manager skips the pip step, and this node needs nothing beyond torch, which ComfyUI already ships.

The node title is Chinese, so search switch or 任意切换; the pack registers English aliases for exactly this reason.

Where people get burned

The honest one: a fallback switch makes a graph harder to read, and this is the same argument that produced the "Please stop using the Anything Anywhere extension" backlash the KB records. When slot 2 wins, nothing on the canvas tells you slot 2 won. If you're debugging, wire the passthrough into a preview node and look at what's actually arriving before you blame the sampler.

Second trap: mixed types. It errors with a clear message, but the place it errors is the switch, and beginners go hunting in the downstream node first. Read the message - it lists the types it saw.

Third: an empty-string input counts as empty. If you're routing a STRING and legitimately want to pass "" down, this node will skip it. That's usually what you want; occasionally it isn't.

CategoryQG-tools/逻辑

Inputs (16)

NameTypeDefaultDescription
any_01opt*—
any_02opt*—
any_03opt*—
any_04opt*—
any_05opt*—
any_06opt*—
any_07opt*—
any_08opt*—
any_09opt*—
any_10opt*—
any_11opt*—
any_12opt*—
any_13opt*—
any_14opt*—
any_15opt*—
any_16opt*—

Outputs (1)

NameTypeDescription
any*—