Nodes/ComfyPanel/ImageMask_Switch
ComfyUI Node

ImageMask_Switch

An A/B selector that doesn't waste a run on the losing branch

By Ginolazy·Created 6 months ago·Updated 2 days ago· 23
ImageMask_Switch
  • image_true
  • mask_true
  • image_false
  • mask_false
  • image
  • mask
switchtrue

ImageMask_Switch is the A/B image-and-mask selector that's actually smart about what it executes. A boolean switch picks between a "true" branch (image_true + mask_true) and a "false" branch (image_false + mask_false), and the chosen pair comes out of the image and mask outputs. That much is a stock A/B switch. The part that's worth knowing about is the lazy evaluation: only the branch you selected ever runs.

Here's the difference in practice, because it changes how you build. With a plain switch (like this pack's own ImageMask_Swap), both upstream branches execute on every queue run, and then the switch picks one. If branch B is a heavy process - a full inpaint, a second sampler pass, an expensive segmentation - you pay for it even when the switch is pointing at A. This node declares all four inputs as lazy, and implements check_lazy_status to tell ComfyUI which inputs it actually needs for the current value of switch. ComfyUI honors that: the losing branch isn't queued, isn't computed, doesn't touch your VRAM or your run time. That's the mechanic the KB's node-plumbing doc describes as the "A/B switch" shape done right - the selector, not the graph, decides what executes.

The schema is minimal on purpose. switch defaults to true. The four inputs are optional (so you can wire up just the branch you have), and the outputs are image and mask. No type gymnastics, no hidden parameters.

Where it earns its keep: A/B testing two expensive alternatives - two different inpaint branches, a refiner on or off, two reference-image pipelines - inside a single workflow you toggle between. If both sides are cheap, the lazy behavior is just a bonus and ImageMask_Swap is simpler to reach for. If one side costs you minutes, this node is the one that makes A/B testing practical in a single graph.

One honest caveat: lazy evaluation is a ComfyUI mechanism that some nodes don't fully participate in - if a node upstream of the losing branch is itself an output node or has side effects, ComfyUI's cache rules can still cause it to run. For typical model-processing chains it works as advertised. And remember the mask follows its image: image_true pairs with mask_true on the true side, and they stay paired through the outputs - no crossed wires.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/Ginolazy/ComfyPanel
# restart ComfyUI

or ComfyUI Manager → "ComfyPanel". No models, standard pack deps. If you toggle the switch and the previously-chosen branch still runs, it's almost always ComfyUI's cache deciding the other branch changed - check whether there's an output node on the losing path, and know that's a cache interaction, not a broken switch.

CategoryComfyPanel/Image & Mask

Inputs (5)

NameTypeDefaultDescription
switchBOOLEANtrue
image_trueoptIMAGE
mask_trueoptMASK
image_falseoptIMAGE
mask_falseoptMASK

Outputs (2)

NameTypeDescription
imageIMAGE
maskMASK