Nodes/ComfyUI_Lam/条件选择器
ComfyUI Node

条件选择器

A lazy case/switch for arbitrary ComfyUI values

By yanlang0123·Created 2 years ago·Updated 11 days ago· 77
条件选择器
  • switcher
  • case0
  • case1
  • ?

LamSwitcherCase (条件选择器) is the pack's take on a switch statement for arbitrary node values: you feed it a switcher value and a set of case0, case1, … inputs, and it returns the case matching the switcher. What makes it worth using over a pile of reroute-and-bypass hacks is lazy evaluation - it only executes the branch you actually selected, so the other cases don't run, don't waste GPU time, and don't error.

In a normal ComfyUI graph, every connected node executes regardless of which branch "matters" - that's why people end up hand-bypassing nodes. This node inverts that: the unselected branches are declared lazy and simply never compute. The author's own description spells out the intent: "根据switcher值选择执行哪个case流" - pick which case-stream runs based on the switcher value.

How the switcher works

The switcher input is polymorphic:

  • An int or numeric string (0–19) selects that one case: 0case0, 1case1, and so on up to 20 hidden case slots (case2case19 exist behind the scenes; only case0 and case1 show on the node by default).
  • A list of ints returns a list - each entry pulls its matching case, so you can fan one switcher across several cases at once.

Anything else (say, a tensor) raises a "Invalid input type for 'switcher'" error, so keep it to numbers and lists of numbers.

Inputs and outputs

  • switcher - the selector (int, numeric string, or list of ints).
  • case0, case1 - the two visible case inputs. Any type (*), since a case can carry anything from an image to a model reference.
  • ? (output) - the selected case's value (or a list of values if you passed a list). The output is named ?, which is honest about "you get whatever matched."

Install

Part of the ComfyUI_Lam pack:

cd ComfyUI/custom_nodes
git clone https://github.com/yanlang0123/ComfyUI_Lam

or via ComfyUI Manager, then the README's install + 修改文件 steps.

Gotchas

Only two case inputs are visible on the node itself - to use cases 2–19 you have to add them via the hidden inputs, which in practice means the node was designed for use in workflows the author built, not for casual extension. Keep the switcher a number: feeding it a string like "1" works, but anything that isn't a clean integer or list raises that error. And lazy inputs mean if you want every branch to run (to warm up models, say), this is the wrong tool - that's what plain nodes are for.

Categorylam

Inputs (3)

NameTypeDefaultDescription
switcher*
case0*
case1*

Outputs (1)

NameTypeDescription
?*