Nodes/ComfyUI-YCNodes/Mask Condition Switch (YC)
ComfyUI Node

Mask Condition Switch (YC)

Route between two masks based on a text match — a tiny switch for loop workflows

By yichengup·Created 2 years ago·Updated 4 months ago· 48
Mask Condition Switch (YC)
  • mask_a
  • mask_b
  • mask
  • is_matched
input_text
preset_text
case_sensitivetrue

A conditional switch for masks: compare two strings, and if they match, pass mask_a through; if they don't, pass mask_b. It's a two-input router built on a string comparison, and it also tells you the match result as a boolean. On its own it's a curiosity; wired into a loop or a batch it's how one workflow picks between different masks without you standing there.

What it's actually for

The classic use is per-iteration choice. You're running a batch or a loop where each pass carries some text - a filename, a tag from a CSV, a label your wildcard or index node produced - and the mask you want depends on that text. "If the tag says closeup, use the face mask; otherwise use the full-body mask." That's this node. Same pattern as YC Text Condition Switch (which routes images) and YC Universal Gate (which routes anything), but specialized for masks.

How it works

Plain exact string comparison. input_text is compared to preset_text, and case_sensitive decides whether "Portrait" equals "portrait". On a match, the output is mask_a; otherwise mask_b. The is_matched output carries the raw boolean so you can wire it onward - into a gate, a counter, or just to skip a step downstream.

Two honest gotchas live in the "empty" behavior. If the branch you need isn't connected - matched but no mask_a, or unmatched but no mask_b - the node returns a 1×1 empty mask instead of erroring. That's convenient for not crashing the graph, but a 1×1 mask can silently do nothing (or weird things) downstream. And the comparison is an exact match; leading/trailing spaces or a \n from a multiline source will make a visually identical string fail the test.

Inputs and outputs

  • input_text - the text to test
  • preset_text - what to compare against
  • case_sensitive - default on
  • mask_a - passed when matched
  • mask_b - passed when not matched

Outputs: the chosen mask and the is_matched boolean.

Install

Ships in ComfyUI-YCNodes. ComfyUI Manager → search "ComfyUI-YCNodes" → install, restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/yichengup/ComfyUI-YCNodes

Dependencies: torch, numpy, pillow, opencv-python, scipy - no model downloads, nothing special.

Where people get burned

  • The 1×1 empty fallback. Wire it as if both branches might be missing. If your graph suddenly produces a tiny or blank mask, check whether the branch you expected was actually connected.
  • Exact match only. No substring matching, no fuzzy logic - it's ==. If your text arrives with whitespace or line breaks, the match fails and you get mask_b plus is_matched = false.
  • It's not a general switch. It routes exactly two masks, on exactly one string comparison. If you need a many-way mask selector, reach for an index-based switch instead.

It's a small, single-purpose logic node - but in batch workflows, a string-gated mask switch is exactly the piece that turns "change it manually every run" into "let the workflow decide."

CategoryYCNode/Logic

Inputs (5)

NameTypeDefaultDescription
input_textSTRING输入文本,将与预设文本比较
preset_textSTRING预设文本,用于与输入文本比较
case_sensitiveBOOLEANtrue是否区分大小写
mask_aoptMASK当输入文本与预设文本匹配时输出的遮罩
mask_boptMASK当输入文本与预设文本不匹配时输出的遮罩

Outputs (2)

NameTypeDescription
maskMASK
is_matchedBOOLEAN