Skip to content
Bit Quirky Round Trip
Visual Scripting

Search documentation

All topics and APIs

Close returns focus to Search.

What are you looking for?

Try a common topic or a C# feature.

Browse the reference instead

Esc closes · Tab reaches results · Enter opens the focused link

v1.0.0
Menu

Common shapes

Six common flow patterns that keep appearing in gameplay code, each shown with a method from the Platformer sample.

On this page

A method can look unique in C# while using a shape you already know. Gameplay code keeps returning to six common shapes. Each page states the pattern in general terms, traces its diagram, shows the source, and makes one small extension visible.

Each shape is shown with one method from the Platformer sample, a sample from the optional Round Trip Sample - Platformer package and that you import into a test project, so every page names a real class. Once its folder is indexed, the same reading works on any method in your project that has the shape.

Compare three control-flow shapes

Select a screenshot to enlarge it.

Door Enter diagram with three branches leading to EXIT before completion work.
Figure 1. Example: stop before doing work Each refusal route ends at EXIT. Follow the false outputs to find the completion work behind all three checks.
EnemyStateMachine ApplyState with three switch case outputs and separate rows of calls.
Figure 2. Example: pick one state A different method uses SWITCH instead of a chain of refusals. Each state starts its own row; rows are alternatives, not steps that all run.
PlayerMotor UpdateGrounded with a FOR body checking contacts and exiting on a match.
Figure 3. Example: look for a match Here FOR repeats the contact check. The route through the grounded SET and EXIT ends the method at the first qualifying contact.
  • Guard clause: leave a method early when its input or state rules out the work. In the sample, Door.Enter leaves early for a missing player, locked goal, or completed level.
  • Count and threshold: turn a running total into a yes or no decision. In the sample, ScoreCounter.OnCoinCountChanged turns a coin total into a door decision.
  • Switch on a state: give each enum value its own calls. In the sample, EnemyStateMachine.ApplyState does this for each enemy state.
  • Turn at the edge: reverse direction only when a bound is reached while moving toward it. In the sample, EnemyPatrol.FixedUpdate reverses at the left or right bound.
  • Scan a list: visit items until the first match, then stop. In the sample, PlayerMotor.UpdateGrounded finds the first contact normal that points up past the grounding threshold.
  • Call a neighbor: hand work to the components that own it. In the sample, PlayerController.CollectCoin passes work to the coin, score, HUD, and audio components.

Read the flow guides when the white execution wire is the question. Read calls and data when the component receiving a call, a value passed into it, or its returned value is the question.

  • Guard clause: start with the smallest control-flow shape.
  • Flow: learn branches, loops, switches, returns, and throws.
  • Calls and data: learn calls, reads, writes, operators, and values.
Full-size image