Switch Mask
A lazy A/B switch for masks that doesn't waste VRAM
- on_true
- on_false
- ui_widget
- mask
- mask_list
Every workflow eventually wants the same graph to do two different things. Route one mask today, another tomorrow, flip it with a boolean instead of rewiring. LF_SwitchMask is exactly that: a classic A/B switch, but typed for masks, with one genuinely nice property - it's lazy. Only the branch you're actually selecting gets evaluated, so the expensive path you're not using doesn't burn VRAM or time. It's the mask-router from the lf-nodes logic family.
How it works
The mechanism is the interesting bit, because it's what separates this from a dumb selector. A normal switch node forces both inputs to be computed before it picks one - which is wasteful when one branch is a heavy mask generator (SAM, a mask-from-depth pass, an inpainting prep) and you're only using the other. LF_SwitchMask implements ComfyUI's lazy-input protocol: it declares a check_lazy_status that tells the engine "I only need on_true if the boolean is true, otherwise I only need on_false." The engine then skips whatever branch you didn't pick. In a big graph that can be the difference between a fast flip and re-running half your pipeline.
The boolean state also gets pushed to a small progress-bar-style widget on the node, so you can see at a glance which mask is live.
The inputs that matter
- on_true (MASK) - returned when the condition is true.
- on_false (MASK) - returned when the condition is false.
- boolean (BOOLEAN, default false) - the switch. This is the widget you convert to an input and wire to a logic node, a primitive, or a control panel.
Outputs are mask (the selected mask) and mask_list (the same as a list).
Install
Part of lf-nodes:
- ComfyUI Manager: search "LF Nodes", install, restart.
- Manual:
cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/lf-nodes.git, restart.
No models. This is pure plumbing - nothing to download beyond the pack.
Common issues
- "Why is my unselected branch still running?" If the branch upstream is a plain node (not lazy), the engine can only skip it if this node's lazy request propagates. Nodes that must run (output nodes) upstream of
on_truecan still force evaluation. The lazy behavior applies where the engine can honor it - it's not a promise for arbitrary graphs. - "The boolean does nothing." Check which widget is the source. If you typed
truein the boolean widget, that works; if you wired a primitive into it, the wire wins. Same footgun as every ComfyUI switch. - Type mismatch. This is a MASK switch, not an ANY switch. Feed it images or latents and it won't connect. If you need to switch mixed types, you want an any-type switch from a pack like rgthree - this node is deliberately single-type.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| on_true | MASK | Value to return if the boolean condition is true. | |
| on_false | MASK | Value to return if the boolean condition is false. | |
| boolean | BOOLEAN | false | Boolean condition to switch between 'on_true' and 'on_false' values. |
| ui_widgetopt | LF_PROGRESSBAR | [object Object] | — |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| mask | MASK | Final output mask. |
| mask_list | MASK | List of all output masks (if any). |