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

Guard clause

Understand early exits, choose between a right-rail guard and a canvas branch, then build a door's refusal paths.

A guard clause ends a method early when it should do no more work. In the Platformer sample, the goal door refuses a missing player, a locked door, or a repeated completion before it finishes the level.

For a required reference or a null-safe call, start with the right rail’s Guards card. It keeps repeated safety checks off the canvas so the game’s work is easier to follow. A gameplay decision or a check with extra work on its refusal path can use explicit BRANCH and EXIT nodes.

The steps below teach that explicit early-exit flow using the sample’s Door class. You can follow them without reading C#. After Compile, recognized checks may appear in the method’s or node’s GUARDS card instead of as separate branches; their behavior stays in the script.

The goal’s trigger fires more than once while the player stands in it. The door has to ignore a missing player, refuse entry while it is locked (with a message in the Console), and do nothing once the level is already complete. Only a valid first entry finishes the level.

  • A trigger or collision can fire again and again, and only the first one should count.
  • Something the method needs may be missing, such as a player that has already left the scene.
  • The object has states where it should refuse, such as a locked door or a pickup that is already spent.

Build the entry node and the first guard

  1. Create TryEnter

    Open Tools > Round Trip > Graph view, press Cmd/Ctrl+O and choose Door. Press the + on the Methods section of the left rail. A name box holding NewMethod appears; type TryEnter and press Enter. The canvas shows one magenta entry node titled TryEnter with an Exec pin.

    Clip: the pointer presses Ctrl+O. The class picker opens and Door is chosen; it clicks + on Methods, types TryEnter and presses Enter. A magenta TryEnter entry node lands alone on the canvas with a white exec pin. While the pointer presses the plus on Methods, it is highlighted with an arrow pointing at it.
    The whole Graph view with Door open. The plus beside Methods on the left rail is highlighted, with an arrow pointing at it.
  2. Add the player input

    In the right rail’s Inputs card, press +. A row with a type dropdown and a name box appears. Choose PlayerController as the type and type player as the name. A magenta player pin appears on the entry node.

    Clip: + is pressed on the right rail's Inputs card; a row with a type dropdown and a name box appears. The type chooser opens, PlayerController is typed and picked, then player is typed into the name box. A magenta player pin appears on the entry node. While the pointer presses the plus on Inputs, it is highlighted with an arrow pointing at it.
    The whole Graph view with the new TryEnter entry node on the canvas. The plus on the right rail's Inputs card is highlighted, with an arrow pointing at it.
  3. First guard: a missing player

    First guard, a missing player. Right-click blank canvas. The All actions menu opens with a Search box at the top. Under flow control, pick branch. A yellow node with BRANCH in its header appears, with Exec and Condition on its left and true and false on its right. Drag from the entry node’s Exec pin to the branch’s Exec pin. A white wire joins them.

    Clip: the pointer right-clicks blank canvas, the all actions menu opens with a search box at the top, and under flow control it clicks branch. A yellow BRANCH node lands, then a white wire is dragged from the entry node's exec pin to the branch's exec pin. While the pointer rests on the pin to drag from, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the branch row.
  4. Feed the first guard's condition

    Right-click again and type Equals, then pick the Equals row with the = icon. A red EQUALS node appears with Left and Right inputs and a Result output. Drag the entry node’s player pin onto Left; a purple wire appears. Click the empty Right pin and type null. Drag Result onto the branch’s Condition. The red wire is the color of a yes or no value.

    Clip: the pointer right-clicks and types Equals, then picks the Equals row. A red EQUALS node lands. The entry node's player pin is dragged onto left, null is typed into right, and Equals' result is dragged onto the branch's condition. While the pointer rests on the player pin and on Equals' result pin, each is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the Equals row.
  5. Stop on a missing player

    Right-click and pick return under flow control. A magenta node headed EXIT appears with one Exec input. Drag the branch’s true output to it. A missing player now stops here.

    Clip: the pointer right-clicks, picks return under flow control, and a magenta EXIT node lands. The branch's true output is dragged onto its exec pin. While the pointer rests on the branch's true output, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the return row.

Add the locked-door guard

  1. Second guard: a locked door

    Place another branch and drag the first branch’s false output to its Exec. Right-click, type IsUnlocked, and press get on its row. A red IsUnlocked pill appears.

    Place another Equals and wire the pill into Left. Click Right, then tick and untick its checkbox to commit false. Wire Result into the new branch’s Condition.

    A second branch receives the first branch's false output. An IsUnlocked pill feeds Equals; its other input is committed as false, and Result feeds the new branch's Condition. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the branch row, then the get button on the IsUnlocked row, then the Equals row.

Finish the refusal paths and completion route

  1. Log the locked-door message

    Right-click and pick Log under logging. A teal Log node appears with a message pin. Drag the second branch’s true output to its Exec. Click message and type "player reached the goal, but it is still locked.", including the double quotes.

    Place a return and wire the Log node’s Exec output into it. This message explains the refusal without continuing to the completion work.

    The second branch's true route reaches a Log call with the locked-door message, followed by an EXIT node. While the pointer rests on the pins to drag from, each is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the Log row, then the return row.
  2. Third guard: already complete

    Place a third branch and wire the second branch’s false into its Exec. Right-click, type IsCompleted, and press get. Drag the red pill straight onto Condition; a yes or no value needs no comparison node.

    Wire true to a new return with nothing in between. Repeated triggers after completion now stop quietly.

    A third branch receives the second branch's false output. IsCompleted feeds Condition directly, and true reaches another EXIT node. While the pointer rests on a pin or pill to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the branch row, then the get button on the IsCompleted row, then the return row.
  3. Mark the level complete

    Right-click, type IsCompleted, and press set. A dark IsCompleted node appears with SET in its header and a Value checkbox. Tick it, then wire the third branch’s false into its Exec.

    An IsCompleted SET node has its Value checkbox checked and receives the third branch's false route. While the pointer rests on the branch's false output, it is highlighted with an arrow pointing at it.
  4. Refresh the HUD and play the sound

    Get a _hud pill. Drag from its output pin onto empty canvas and choose RefreshComplete from the member menu. Its Target is already wired from the pill. Wire the SET node’s Exec output into this call.

    Do the same with an _audio pill and PlayCompletion, continuing the white wire from RefreshComplete.

    The success route calls RefreshComplete on _hud, then PlayCompletion on _audio. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the get button on the _hud row, then the RefreshComplete row, then the get button on the _audio row, then the PlayCompletion row.
  5. Read the player's game object

    Drag from the entry node’s player pin and press get on gameObject. The purple gameObject pill lands to the right, its wire running under the cards.

    A gameObject pill is placed from the entry node's player pin. Its wire runs under the cards to the right. While the pointer rests on the player pin to drag from, it is highlighted with an arrow pointing at it. The menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the get button on the gameObject row.
  6. Deactivate the player and log

    Drag from the gameObject pill and choose SetActive. Click its value pin, then tick and untick the checkbox to commit false. Wire PlayCompletion’s Exec output into SetActive.

    Place a Log, wire SetActive’s Exec output into it, and type "goal reached: level complete." into message, including the quotes.

    SetActive is called on the gameObject pill with its value committed as false, wired after PlayCompletion, then a Log node carries the completion message. While the pointer rests on a pill or pin to drag from, it is highlighted with an arrow pointing at it. Each menu choice is highlighted with an arrow pointing at it while the pointer rests on it: the SetActive row, then the Log row.
  7. Compile

    Press Compile in the toolbar. Look in GUARDS for any recognized checks lifted from the canvas.

    The whole Graph view with the finished TryEnter graph. The toolbar Compile button is amber and highlighted with an arrow pointing at it, because the canvas holds changes that are not in the C# file yet.
    TryEnter after Compile, with three guard branches and their exit paths above the IsCompleted SET node and completion calls.

For a reference the class needs, such as an unassigned _hud, the right rail’s Guards card can add the stop for you. Press Add a check, pick the value in the Require a value list, and choose what happens under If _hud isn’t set…, for example Warn and skip the rest of this method.

If you also work in C#, this is the sample’s Enter method, the finished shape the steps build toward. Your TryEnter writes the same three early exits in the same order, whether a check reads back as a branch or in GUARDS. An early-exit branch is written as an if with the rest of the method after it, so the completion work stays outside the refusal blocks.

Keep each reason on its own node. Folding every reason into one long condition would hide which guard owns the locked-door message.

Round Trip also reads the plainest guard on a class value as a guard: an early exit at the top of a method, on a bool field or property, with nothing else on its route. It is listed in the method’s Guards card as a guard on that bool, and its style editor is headed If _isConfigured is false… for a bool named _isConfigured. Edits made in that card wait for the toolbar Compile; the card’s own banner offers only Discard. The locked-door guard in Enter stays an ordinary branch, because its route logs before it returns.

When it goes wrong

SymptomCheckFix
The completion nodes still run for a missing player.Follow the white wire from the first BRANCH node's true output.Drag that true output to a magenta EXIT node placed from return under flow control.
The locked message appears after the level is complete.Look at which yellow node's true output leads to the Log node.Keep the Log node on the true route of the IsUnlocked guard, then Compile.
Full-size image