Logic node

Switch

Selects one of any number of inputs by integer index and passes it through unchanged. Connect as many data sources as you need to the auto-numbered dynamic inputs, then steer the Index to choose which one reaches the output — a data multiplexer for building scene selectors, A/B comparisons, and preset systems. Because the ports carry the .any type, a Switch can route floats, colors, strings, structures, or even generator textures.

Inputs

PortTypeDefault
IndexPicks which numbered input passes through. Counting starts at 0, and negative numbers count back from the end, so -1 is the last input; anything outside the range falls back to Default. ALSO accepts an ARRAY: each element picks its own input, Result becomes an array — a lookup table in one node.int0
Ease Time0 (default) = instant cut, exactly the classic Switch. Above 0 an index change becomes a TRANSITION: numeric values (and arrays, element-wise) blend to the new slot over this many seconds, both sides live. A switch mid-transition fades from the current mix. Non-numeric values cut at half-way.float0
Ease TypeThe transition curve: Linear, Ease In, Ease Out, Ease In-Out, Smooth (softest S) or Expo (snappy start, long tail). Only shown while Ease Time is above 0.int3
DefaultThe value sent when the index points nowhere — out of range, or no numbered inputs connected yet. Any type works.any—

Outputs

PortType
Resultany
IndexPicks which numbered input passes through. Counting starts at 0, and negative numbers count back from the end, so -1 is the last input; anything outside the range falls back to Default. ALSO accepts an ARRAY: each element picks its own input, Result becomes an array — a lookup table in one node.int
Countint
Progressfloat
Finishedbool
Transitionstructure

How It Works

Switch is a pure, stateless selector — it holds no memory between frames and simply forwards whichever input the current Index points at.

Dynamic inputs. The node supports dynamic inputs: connecting a cable to the trailing wildcard port creates a new numbered input (auto-indexed naming), inserted after the Default port. Inputs are addressed in order: the first dynamic input is index 0, the second is index 1, and so on.

Type locking. Every frame the node scans its dynamic inputs for the first connected cable and locks all dynamic inputs, the Default input, and the Result output to that source's port type. If no dynamic input is connected, the type is taken from the Default port instead. This prevents mixing incompatible data (for example an image on one input and a float on another) and makes the selected type visible in the graph as cable colors. When every cable is disconnected, the ports revert to .any (white).

Index resolution, frame by frame:

SituationResult outputIndex output
No dynamic inputs existValue of Default0
Index in 0 … Count−1The selected dynamic inputThe resolved index
Negative index within rangeCounted from the end (-1 = last input)The resolved positive index
Index out of rangeValue of DefaultIndex clamped to 0 … Count−1

If the selected input has no value (nothing connected to that particular numbered port), the node falls back to Default.

Count always reports how many real dynamic inputs currently exist (the trailing wildcard and ghost ports are not counted), so downstream logic can adapt when you add or remove inputs.

Parameters in Depth

Index (int, default 0) — which input to pass through. 0 selects the first dynamic input. Negative values count backwards from the end: -1 is the last input, -2 the second-to-last. Any value outside the valid range (after negative resolution) routes Default to the output instead — nothing is ever silently wrapped. Drive this from a Counter, MIDI Receiver, or Compare chain for live switching.

Default (any) — the fallback value, used whenever the index is out of range, the selected port is empty, or no dynamic inputs exist at all. Leaving it unconnected outputs a null value in those cases, so wiring a sensible fallback (a Constant, a neutral color, an empty texture) is good practice for patches where the index is driven by unpredictable data.

Dynamic inputs (auto-numbered, any) — the actual selectable sources. All of them are forced to a single common type (see Type locking above); the first connected cable decides that type for the whole node.

The outputs mirror the selection: Result carries the chosen value, Index reports the index that was actually used (clamped into range even when Default was substituted), and Count reports the number of dynamic inputs.

Use Cases

  • Scene switcher: several generator chains (Circle 2D, Rectangle, L-System, Magic Storm) each feed a Switch dynamic input; a Counter driven by Keyboard → Switch (Index) → Canvas steps through visual scenes with a key press.
  • Beat-synced color palettes: multiple RGB Color nodes → Switch; Audio Beat Detection (Kick) → Counter (Limit: Loop) → Switch (Index) cycles the fill color of a Circle 2D on every kick drum.
  • MIDI program select: MIDI Receiver (note or CC value) → Math (scale to input count) → Switch (Index) chooses between different Gradient nodes feeding a Plexus.
  • A/B compare with fallback: two candidate processing chains enter inputs 0 and 1, a Constant enters Default; Compare → Switch (Index) flips between them, and any out-of-range test value safely shows the Default look.
  • Automated playlist: Timer (Done) → Counter → Switch selecting between several Video Player / Image sources, advancing to the next visual when each timer cycle completes.
  • Text states: several Constant (string) nodes → Switch → Text as Image → Canvas to display status labels ("READY", "LIVE", "PAUSED") selected by patch logic.

Tips

  • The Index output is useful even when you drive Index from noisy data — it tells you which input actually won after negative-index resolution and clamping, and can drive a matching UI Text readout.
  • Because all inputs snap to the first connected type, connect your intended data type first; a stray cable of the wrong type will lock the whole node to it until disconnected.
  • Switch selects between values every frame — all upstream branches still evaluate. For image sources, prefer disabling unused generator chains (Enable = false) if GPU cost matters; Switch does not "power down" the branches it isn't showing.
  • Negative indexing pairs nicely with Count: Index = -1 always tracks the most recently added input without renumbering anything.
  • For boolean two-way selection a Compare or Logic node feeding Index (0/1) is the idiomatic pattern; for value-range branching, consider Remap or Math Expression to compute the index.
  • Related nodes: Hold Value (freeze a single stream instead of choosing between streams), Array Get (index into one array cable instead of N separate cables), Counter (the natural Index driver).

Open Switch in the interactive catalog →

Switch is one of 381 nodes in Grafit Pro.

Free download. Every feature for 7 days, no card. Then €99.99 once — or keep playing your projects as a Player.

More Logic nodes