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

Guards

Keep prerequisite checks and missing-reference handling in the right rail, so the canvas stays focused on what your game does.

The coin pickup needs a HUD before it can update the score display. A guard lets you say what should happen if that HUD is missing, without drawing a separate check and branch before the update.

A prerequisite is something that must be ready before work can continue. A missing reference means a value points to no object: for example, a HUD slot left empty in Unity’s Inspector. C# calls that value null.

Repeated missing-value checks can fill a diagram with comparisons, branches and early exits before you reach the game’s actual behavior. Round Trip lifts recognized checks into the right rail so the canvas is cleaner and easier to read. You can follow the coin pickup’s calls, then inspect its safety checks in one place.

The check still runs and still lives in the C# script. Lifting it changes how it is shown, not what the game does. Reading an existing script writes nothing; changing a guard becomes a draft until you press Compile.

What you want to decide Where to look
Can this method do its work? For example, is its HUD assigned? Select the method in the left rail, then open GUARDS in the right rail. The header’s guarded values badge jumps to it.
What if this particular call or read has no object? For example, optional pickup audio. Select the node, or click its pin’s shield marker, to see that node’s GUARDS card.
Which gameplay path should run? For example, take damage or block a hit. Keep that decision on the canvas as a BRANCH. Checks that do not match a recognized guard also stay as nodes.

Choose what happens when a value is missing

Section titled “Choose what happens when a value is missing”

For a required object, Warn and skip the rest of this method is the usual starting point. It avoids using the missing object and explains the skipped work. The project’s available patterns determine which choices appear.

Outcome What it means
Stop with an error Uses the project’s assertion/error pattern. Expand Advanced · show code to see the exact C#; assertion behavior depends on that pattern and Unity’s assertion settings.
Warn and skip the rest of this method Runs the configured warning action, then returns before the rest of the method. A method that gives back a value also needs a return value.
Warn but carry on Runs the configured warning action and continues. Use only when the remaining work is safe without the value; a warning alone cannot prevent a later missing-reference error.

A yes-or-no variable or property can be a flag guard, such as “the level is configured”. Its heading reads If followed by the name and is false…. Flag guards are checked individually; they cannot join a combined missing-reference check.

Require a value for the method

  1. Open the method

    Click the method you are building in the left rail. Scroll the right rail to GUARDS, or click the header’s guarded values badge. An empty card reads No required values yet.

    The Round Trip graphs window with GuardExamples.ReportScore open. The ReportScore row in the Methods list of the left rail is highlighted with an arrow pointing at it, and so is the empty GUARDS card in the right rail, reading No required values yet.
  2. Add a check and pick the value

    Press Add a check. In Require a value, filter the list and tick the value the method needs, such as _hud. Press Require this value.

    The same window with the Add a check button of the empty GUARDS card highlighted and an arrow pointing at it.
    The require a value picker filtered to _hud, with its checkbox ticked and Require this value enabled. The _hud row and the Require this value button are highlighted, with an arrow pointing at the button.
  3. Choose the outcome

    Expand the new check’s row if needed. Under If _hud isn’t set…, choose the If check option that ends in return. Edit Message if you want different words.

    The expanded _hud check with the If check, return style selected and highlighted, with an arrow pointing at it, and a Previewing your changes banner.
  4. Compile

    Press Compile in the toolbar.

    The window with the guard still a draft: the Compile button in the toolbar is lit and highlighted with an arrow pointing at it, and so is the Compile button in the Previewing your changes panel at the top of the right rail.
    After Compile the method header reads 1 guarded value and the GUARDS card shows _hud as Required, both highlighted. The canvas keeps its five nodes and the toolbar Compile button is grey.
  • Tick several values in the picker to Combine 2 values into one check. They share one outcome; the header counts the values, not the rows. Add another value to this check grows the group, and Split out makes one value a separate check.
  • Customize changes just this check; Reset to default restores the current project default. A customized Message has its own Revert to default action.
  • Remove stages removal of a check. Discard drops the guard draft. Press Compile to save a change you want to keep.
  • Value renamed or removed means the check needs Replace value, or removal, before you Compile.

An audio player can be optional even when the score counter is required. A node guard can skip PlayCoin when _audio is missing while letting the rest of the pickup method continue. This differs from a method guard that skips all remaining work.

Handle a missing value at one node

  1. Select the call

    Select the call or member-read node you want to protect. For example, select PlayCoin with its target wired from _audio.

    The PlayCoin node is selected and highlighted with an arrow pointing at it; _audio is wired to its target. In the right rail the GUARDS card reads No checks on this value yet, with its Add a check button highlighted.
  2. Choose Null-safe read

    Press Add a check. Under How should it be guarded?, choose Null-safe read to skip access when the object is missing.

    After Add a check was pressed on the PlayCoin node, the GUARDS card shows How should it be guarded? with two forms. The Add a check button and the Null-safe read form, _audio?.PlayCoin(), are highlighted, with an arrow pointing at the form.
    The node rail after Null-safe read was chosen. A pending _audio null-safe call marked New is highlighted with an arrow pointing at it, under a Previewing your changes banner.
  3. Compile

    Press Compile. Click the shield marker on the call’s target pin, then expand the guard row to inspect it or Remove it.

    The window with the null-safe check still a draft: the Compile button in the toolbar is lit and highlighted with an arrow pointing at it, and so is the Compile button in the Previewing your changes panel.
    After Compile, PlayCoin's target pin shows a shield marker and the GUARDS card reads one guarded value: a recognized null-safe call. The shield marker and the guard row are highlighted, with an arrow pointing at the marker.

Use guards without changing the project setup first. When you want a shared warning style, different defaults, or recognition of your team’s own C# checks, open Edit > Project Settings > Round Trip > Guard recognition. These rules are shared with the project; the toolbar gear opens personal Preferences, a different page.

Guard rules has the setup steps and a verification checklist. For one guard’s exact pattern and generated C#, expand Advanced · show code on its row. You can skip that section when working visually.

If you also work in C#, this is an existing silent guard on _hud ahead of the HUD call in a RefreshHud helper on PlayerController in the Platformer sample. It has no warning call; adding or changing a check uses the pattern chosen in your project.

Round Trip also reads matching checks already in a script as guards, including a yes-or-no variable checked before work continues. A check that does not match stays visible as ordinary nodes and wires. The Guard clause pattern teaches explicit early-exit branches when you want to build the flow yourself.

When it goes wrong

SymptomCheckFix
The picker says Every value is already requiredRead the rows on the GUARDS card.Edit an existing check, or use Add another value to this check, instead of adding a duplicate.
A row says Needs a returnLook for the What this method returns when it skips row.Press Choose what to return and pick the value.
A row says Value renamed or removedLook in the Variables list for the value that replaced it.Press Replace value and pick it, or press Remove.
Compile is off and says Fix the pending change that needs attention before compilingLook on the GUARDS card for a row with a warning word, such as Needs a return.Use the button on that row, or remove the check, then Compile.
Full-size image