Nodes/rgthree's ComfyUI Nodes/Any Switch (rgthree)
ComfyUI Node Runs on cloud

Any Switch (rgthree)

Any Switch (rgthree)

By rgthree·Created 3 years ago·Updated 13 days ago· 3,294
Any Switch (rgthree)
    • *

    Any Switch lets you build a fork in your workflow that you flip with a mute key. Feed it several inputs of the same type, and it passes along the first one that isn't empty. Toggle the earlier ones off - by muting whatever feeds them - and the next live input takes over. It's the general-purpose sibling of rgthree's Context Switch: same idea, but for any single type instead of a whole context bundle.

    Why you'd reach for it

    You've got two ways to produce an image and you want to switch between them without rewiring: maybe a text-to-image path and an image-to-image path, and you flip which one drives the rest of the graph. Or three different upscalers and you pick one per run. The naive approach is a selector widget - "input 2, please" - but rgthree deliberately doesn't do that, and the reason is the whole point of the pack.

    A selector-style switch still runs every input, then throws away the ones you didn't pick. That's wasted compute, sometimes a lot of it. Any Switch instead chooses the first non-empty input, so when you make the earlier inputs empty (by muting the nodes behind them), those branches never execute at all. No wasted work. That distinction - pick by emptiness, not by index - is why rgthree's switches are the ones people keep.

    The mental model you actually need: muting runs backward

    Here's the thing that confuses everyone at first. ComfyUI does not flow forward from your inputs. When you queue a prompt, it starts at the output nodes (Save Image, Preview Image) and walks backward, pulling in only the nodes that feed them. So to switch a branch off, you don't mute the front of it - you mute toward its output end so the whole path stops being needed. Mute a branch's producing node and its output goes to None (empty), Any Switch skips it and takes the next live input, and nothing on the dead branch runs.

    The clean way to drive this is rgthree's Fast Muter or Fast Groups Muter: a little dashboard of toggles for muting whole nodes or groups with one click. Wire your branches through Any Switch, put the toggles on a muter, and you've got a proper A/B switch.

    Inputs and outputs

    The inputs here are dynamic - the node adds slots as you connect things, so there's no fixed list of named inputs to memorize. You just connect two or more sources of the same type. The important rule: they should all be the same type (all IMAGE, or all LATENT, or all MODEL), because the node has to hand a single consistent type onward.

    The output is a single slot typed * (any) - it takes on whatever type you fed in, and carries the first non-empty input forward to the rest of your graph.

    Installing it

    Any Switch ships in rgthree-comfy. Install through ComfyUI Manager by searching rgthree's ComfyUI Nodes, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/rgthree/rgthree-comfy.git
    

    Restart ComfyUI after. There's nothing else to download - no models, no Python dependencies. It's pure graph plumbing.

    Common issues

    The number-one confusion is muting the wrong end. If you mute the first node of a branch expecting the graph to stop there, you'll usually get an error instead, because something downstream still wants that branch's output. Mute toward the output end of the path so the branch stops being pulled in at all. Get comfortable with that and switches suddenly make sense.

    Second, and this one's subtle: mute, don't bypass. They look interchangeable but they aren't. A muted node outputs None, which is exactly what Any Switch wants to skip. A bypassed node passes its input straight through to its output - so it hands the switch a real, non-null value, and Any Switch dutifully grabs it. rgthree says as much himself when people report this: what you want is to mute those branches, not bypass them. If your switch is picking the "wrong" branch, this is almost always why. (A related wrinkle showed up after ComfyUI's subgraphs update, where bypassed nodes started leaking a stray value - a VAE, say - that the switch then forwarded and errored on. Same root cause, same fix: mute.)

    Third: mixed types. Any Switch expects its inputs to be the same type. Feed it an IMAGE and a LATENT and the wiring gets ambiguous - keep a switch to one type and use a separate switch for another.

    And the usual pack-wide caveat: if the node renders with stacked or broken controls, check whether ComfyUI's Nodes 2.0 frontend is on. The Vue rewrite broke several rgthree nodes, and the standing community workaround is to leave Nodes 2.0 disabled.

    Categoryrgthree

    Inputs (0)

    No inputs

    Outputs (1)

    NameTypeDescription
    **