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

Enums and data classes

Create named states and tunable data types from the Create new class form and the left rail.

An enum is a short list of named choices, such as an enemy’s states. A data class is a type that only holds named values, such as the tuning numbers for a level. You create both from the Create new class form in the Round Trip graphs window, or the New class window, and fill them in from the left rail.

An enum gives each choice a name, so a switch node on the canvas shows one case per name instead of a number. In the left rail, an open enum shows a Members section in place of Variables, with its names in the order you added them and any written value at the end of each row.

A data class holds related values. A ScriptableObject class defines the data an asset can hold; an instance of it can be saved as an asset and shared between objects. Creating the class below writes its script, not an asset instance.

Make an enum when something in the game is always in exactly one of a few states: an enemy that is patrolling, stunned, or defeated; a pickup that is a coin, a key, or a heart; a door that is locked, open, or sealed. Each state then gets its own case on a switch node. The Platformer sample uses an enum named EnemyState with Patrolling, Stunned, and Defeated.

Make a data class when several numbers belong together and a designer should tune them in one place: movement speed, jump force, how many coins open the door. The sample’s LevelRules is a ScriptableObject made only of such values, grouped under Inspector headings.

The New class window
Figure 1. The New class window. The kind dropdown under LOCATION reads class; switch it to enum and the PARENT CLASS cards turn unavailable. Pick ScriptableObject for a data asset.
The ApplyState switch using EnemyState
Figure 2. A finished picture to compare with: an enum in use on a switch node, one case row per state name.

Create an enum and a data class

  1. Open the creation form

    Press the + beside the class chip at the top left of Round Trip graphs. The Create new class form opens.

    The Create new class form is open. The + button beside the class chip at the top left is highlighted.
  2. Name the enum and choose its folder

    Enter WebsiteEnemyState under NAME. Choose Runtime > Examples under LOCATION. Check the proposed script path before creating it.

    WebsiteEnemyState entered as the name, with the Examples folder selected. The NAME box and the LOCATION folder menus are highlighted.
  3. Create the enum

    Choose the enum card under PARENT CLASS, then press Create.

    The enum card and Create action, followed by the imported empty enum. The enum card is highlighted while it is chosen, then the Create button.
  4. Add the first member

    Press + on Members, enter Patrolling, and press Enter.

    Adding Patrolling to the Members list. The + button on the Members header is highlighted.
  5. Add and save the other states

    Add Stunned and Defeated in the same way. Press Compile before continuing.

    Adding Stunned and Defeated, followed by the saved three-member list. The + button on the Members header is highlighted each time it is pressed.
  6. Inspect an enum value

    Select Defeated in the Members list.

    The saved Defeated enum member selected in the Inspector. The implicit value, 2, is highlighted.
  7. Try Remove, then Keep

    With Defeated selected, press Remove under On compile. Press Keep to cancel that change before compiling.

    Marking Defeated for removal and canceling the pending removal with Keep. The Remove button, then the Keep button, are highlighted when they are pressed.
  8. Create the data class

    Open the creation form again. Name the class WebsiteLevelRules, choose Runtime > Examples, select ScriptableObject, and press Create. Wait for Unity to import the new class.

    Creating WebsiteLevelRules as a ScriptableObject and opening the imported class. The ScriptableObject card is highlighted while it is chosen, then the Create button.
  9. Add a variable

    Press + on Variables, enter jumpForce, and press Enter.

    Adding the jumpForce variable to Variables. The + button on the Variables header is highlighted while it is pressed.
  10. Choose the variable type

    Click the row’s type and choose float.

    Choosing float for jumpForce and reviewing the selected type. The type of the jumpForce row is highlighted, then the float entry in the type chooser.
  11. Expose the tunable variable and add a separate constant

    For jumpForce, enable Shown in the Inspector. Under Attributes, press +, choose Header, and enter Movement. Add a separate int variable named MaxJumps, enable Constant, and give it the value 3.

    Exposing jumpForce, adding a Movement header, and creating the separate MaxJumps constant with value 3. The Shown in the Inspector switch, then the + button on the Attributes row, are highlighted.
  12. Compile the data class

    Press Compile.

    Pressing Compile, followed by the saved variables after Unity reloads. The Compile button is highlighted until it is pressed.

If you also work in C#, this is what is written into the script. Both declarations come from the Platformer sample. The EnemyState enum:

One value of LevelRules, with its trailing note:

Editing one value keeps the type’s other values, their attributes, their trailing notes, and their order exactly as they were.

When it goes wrong

SymptomCheckFix
The New class window still offers parent cardsRead the kind dropdown under LOCATION.Choose enum. The parent cards turn unavailable because an enum has no parent.
A new value stays marked New after CompileSelect it and look for an empty name or type, or a Constant with no value.Fill the missing part in the right rail, then Compile.
The right rail warns that saved values moveCompare the before and after numbers in the warning.Keep the change only if you mean to change what saved scenes and assets hold. Otherwise press Undo.
Full-size image