Image and Mask Switch 🦾
Switch four images and their masks together
- images1
- mask1_opt
- images2_opt
- mask2_opt
- images3_opt
- mask3_opt
- images4_opt
- mask4_opt
- IMAGE
- MASK
Image and Mask Switch routes one of up to four image+mask pairs through to a single pair of outputs. You pick a slot with select (an integer, 1–4) and the node forwards that slot's image and its mask together. It's a 4-way selector built specifically so you never have to keep an image and its mask in sync by hand.
The reason this node exists instead of two generic switches: in mask-based workflows, the image and its mask are a matched pair. If you switch them independently, you'll eventually land on image from slot 2 with a mask from slot 3, and you'll spend half an hour wondering why the inpaint region is in the wrong place. This node makes that impossible.
How it works
It's a straight selector: select chooses the slot, and the matching imagesN/maskN values are returned as the IMAGE and MASK outputs. Slot 1 is the only required one (images1); the rest are optional, so a two-slot setup is perfectly fine. If a selected slot has no mask connected, you get None on the mask output - handle that downstream, because a None mask into a mask consumer will error.
The node is marked as an output node, so you get a preview on it as a side effect of using it. It's also a -beyond_nodes pack member, so it follows the pack's convention of being a simple, dependency-free pass-through.
The inputs that matter
select(required, INT 1–4) - which slot to route.images1(required) - slot 1's image. Slots 2–4 are optional (images2_opt,images3_opt,images4_opt).mask1_optthroughmask4_opt(optional) - the mask paired with each image.
Outputs: IMAGE and MASK - the selected pair.
Install
Part of ComfyUI-Beyond_nodes. ComfyUI Manager → search "Beyond_nodes" → install → restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/beyondprompting/ComfyUI-Beyond_nodes
Restart. No extra dependencies.
Common issues
- The mask output is empty/errors. You selected a slot with no mask connected. Either connect one or ensure your downstream accepts a missing mask.
- I want more than four slots. This node stops at four. For more, stack two switches, or use a generic any-type switch and keep image/mask pairing elsewhere.
selectis a widget, not a socket. It is - but you can wire an INT into it to drive the selection programmatically (from a Compare result, a random int, whatever).
The niche is narrow but real: batch-comparing four image+mask setups, A/B testing four inpaint candidates, or switching between four subject composites. When you need the pair to stay together, this is the right tool.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| select | INT | 11–4 | — |
| images1 | IMAGE | — | |
| mask1_optopt | MASK | — | |
| images2_optopt | IMAGE | — | |
| mask2_optopt | MASK | — | |
| images3_optopt | IMAGE | — | |
| mask3_optopt | MASK | — | |
| images4_optopt | IMAGE | — | |
| mask4_optopt | MASK | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| IMAGE | IMAGE | — |
| MASK | MASK | — |