Mask Auto Selector
Pick whichever mask actually got wired in, in priority order
- mask_prior
- mask_alternative
- mask_third
- mask
Workflows that need a mask often have more than one plausible source for it - a SAM detection, a manually painted mask, a fallback region generator - and you don't always want to wire all three into a chain of "if this is empty, use that" switches every single time. MaskAutoSelector collapses that into one node: give it up to three candidate masks in priority order, and it hands you back whichever one is actually present.
What it's for
The clean use case is a fallback chain: your preferred mask source first (say, a precise SAM or face-detection mask), a manual backup mask second, and a generic default region third. Wire all three in and this node picks the best available one without you needing to build the branching logic yourself. It's also just handy as a "this graph should always emit exactly one mask, from whichever of these sources is live right now" adapter when you're iterating on a workflow and swapping mask sources in and out.
How it works
It checks mask_prior first. If that input has something wired to it, that's what gets returned - end of story, the other two inputs aren't even relevant. If mask_prior isn't connected, it falls through to mask_alternative, and if that's not connected either, to mask_third. If none of the three are wired up at all, the node raises an exception rather than quietly passing through an empty or null mask - it fails loud instead of letting a missing mask slide silently into whatever consumes it downstream.
The inputs and outputs that matter
mask_prior(MASK, required) - your first-choice source. Note this input is technically required by the node schema, but functionally the "selection" behavior is what makes this node worth using over just wiringmask_priordirectly - the real value shows up once you also use the optional inputs below.mask_alternative(MASK, optional) - second choice, used only ifmask_priorisn't connected.mask_third(MASK, optional) - third choice, used only if neither of the above is connected.
Output: a single mask (MASK) - whichever one won the priority check.
How to install it
Via ComfyUI Manager: search "ComfyUI-utils-nodes," install, restart. Manually:
cd ComfyUI/custom_nodes
git clone https://github.com/zhangp365/ComfyUI-utils-nodes
Restart ComfyUI. No models involved, this is pure graph logic, so install is fast with nothing extra to fetch.
Common issues & troubleshooting
The behavior worth internalizing before you rely on it: this checks whether an input is connected, not whether the mask flowing through it is meaningfully non-empty. If mask_prior is wired to something that happens to output a fully black (all-zero) mask, that's still "available" as far as this node is concerned, and it'll get returned as-is rather than falling through to mask_alternative. If you need "fall back when the mask is empty" rather than "fall back when nothing's wired in," you'll want to pair this with something like this same pack's MaskAreaComparison upstream to actually test for emptiness, rather than expecting MaskAutoSelector to do that check for you.
And remember the exception behavior: if you leave all three inputs unconnected - easy to do by accident while you're still building out a workflow - the node will throw rather than passing an empty mask along. That's a deliberate design choice (fail loud beats a silent empty mask propagating three nodes downstream before something breaks in a confusing way), but it means you can't leave this node dangling with no inputs wired as a placeholder while you work on the rest of the graph.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| mask_prior | MASK | — | |
| mask_alternativeopt | MASK | — | |
| mask_thirdopt | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |