What is it for?
- Switching values based on a condition
- Branching from the result of
Compare - Choosing between two colors, numbers, paths, or other values
Overview
Selects which of two already-evaluated values to pass downstream from a Bool
condition. It can switch numbers, colors, images, paths, or any other type chosen
with value_type. It is a value selector, not a lazy programming-language if that
skips the unselected branch.
Usage tips
- The basic pattern is
compare.resultโswitch.condition, with condition promoted to an input pin ๐. The output switches when the value crosses the threshold. - Switching images creates a minimal two-state animation.
motion (Blink)โcompareโswitch<Image>alternates between two images. - For three or more choices,
value_selectselects by index more directly. Deeply nested Switch nodes become hard to read. - Choose
value_typecorrectly. UseAnyonly as a last resort because it disables type checking.
Related nodes
compareโ create the conditionvalue_selectโ select among N choices by indexgateโ stop a value instead of choosing oneexpression_boolโ build a Bool from a compound condition
Notes
- You can promote
conditionto an input pin. Connecting the result ofComparedirectly is the go-to setup. - When both sides have upstream nodes, normal graph evaluation runs both upstream
branches before
Switchselects the delivered value. It does not suppress work, side effects, or errors on the unselected side like a lazyifstatement. - Only the selected side is required. The unused side may be unconnected.
- If the selected side is unconnected,
Switchitself emits no warning and produces an empty output. A downstream node may warn that its input is unconnected. - Changing
value_typealso changes the types oftrue_value/false_value/value. - Normally, feed
true_valueandfalse_valuewith the same type. Anyis for advanced use. A connection may be accepted, but if the selected value does not match the type expected downstream, evaluation produces a warning or node error.
Examples
- Switch between
0and1from the result ofCompare- Produces a flag value.
- Switch between two colors from the result of
Compare- Colors the output according to state.
- Switch between two
Pathvalues- Useful when different modes require different shapes.
- Pass the output of
Switch<Float>toMath Op- Sends the branched value directly to the next stage.
- Replace a value for debugging with
Switch<Any>- This is safe only when the downstream setup accepts
Any.
- This is safe only when the downstream setup accepts