Skip to content

Structs, Enums, and Switch on Enum

Structs and enums are small tools that remove big categories of Blueprint confusion. A struct keeps related fields together. An enum replaces piles of contradictory booleans with one named state.

The one-minute version

  • A struct is one value made of named fields: display name, icon, count, weight, price.
  • Make Struct builds a new struct value. Break Struct reads fields out of a struct value. Set Members in Struct changes selected fields while keeping the rest.
  • Structs copy values. Breaking a struct does not create live wires back into the original variable.
  • An enum is one value chosen from a fixed list: Closed, Opening, Open, Closing.
  • Switch on Enum routes execution by the current enum value and gives each named state its own output pin.
  • Use an enum instead of several booleans when only one mode should be true at a time.

A struct answers the question "which values are part of the same thing?"

Struct FInventoryItem
    ItemId (Name)
    DisplayName (Text)
    Icon (Texture2D)
    Count (Integer)
    Weight (Float)

Without a struct, every function that handles an inventory item grows a long pin list:

AddItem(ItemId, DisplayName, Icon, Count, Weight)

With a struct, the contract is clearer:

AddItem(ItemData)

That also makes arrays easier:

InventoryItems = Array of FInventoryItem

Now each array element is one item record instead of several separate arrays that must stay in matching order.

Make, Break, Split, and Set Members

Blueprint gives you several ways to work with struct fields:

Tool What it does Use when
Make Struct Creates a struct value from input fields. You are assembling item data, save data, spawn data, or a function return.
Break Struct Exposes fields from a struct value as output pins. You need to read several fields clearly.
Split Struct Pin Shows fields directly on a node pin. You only need a lightweight field view on one node.
Set Members in Struct Produces a changed struct value with selected fields replaced. You want to update one or two fields without rewiring every field.

The important beginner detail: a struct is a value. If you break a struct, change the loose field pins, and never set the struct variable again, the stored struct did not change.

InventoryItem variable
-> Break FInventoryItem
-> Count + 1
-> Set Members in FInventoryItem Count = new count
-> Set InventoryItem variable to returned struct

For an array of structs, you also need to set the array element back, not just edit a temporary copy in the middle of the graph.

Enums: one named mode

An enum is a fixed list of named choices.

Enum EDoorState
    Closed
    Opening
    Open
    Closing

That one value replaces booleans that can contradict each other:

Bad:
    bIsOpen = true
    bIsOpening = true
    bIsClosing = true

Better:
    DoorState = Opening

The enum does not enforce your gameplay rules by itself. It gives your graph a clear value to test, switch on, save, replicate, or print.

Switch on Enum

Switch on Enum takes one enum input and sends execution out through the pin that matches the current value.

Switch on EDoorState
    Closed  -> Start opening timeline
    Opening -> Ignore interact
    Open    -> Start closing timeline
    Closing -> Ignore interact

This is easier to debug than a chain of boolean branches because the graph shows every possible state. When you add a new enum entry, the switch node can be reconstructed to show the new case.

Use Switch on Enum when behavior changes by named mode:

  • weapon fire mode;
  • menu screen;
  • door state;
  • AI alert state;
  • item rarity;
  • damage type.

Do not use a switch when a plain branch is clearer. A value that is simply true/false can stay a boolean.

When they fail

Structs and enums usually fail by creating stale or impossible state, not by throwing exceptions.

Symptom Likely cause Fix shape
Struct field changed on a pin, but variable stayed old You edited a copy and did not set the struct/array element back. Use Set Members in Struct, then set the owning variable or array element.
Function has a giant struct input nobody understands The struct is too broad. Split into smaller cohesive structs or explicit inputs.
Enum switch never reaches a case The enum variable was never set to that value, or another graph overwrites it. Print the enum value and breakpoint where it changes.
Door is both open and closing You still have old booleans fighting the enum. Make the enum the single source of truth for the mode.
Save/load gives an unexpected enum value Enum entries changed after data was saved. Treat saved enum changes as migration work; prefer stable meanings.

What they do not do

  • A struct does not own live actors or keep object references valid.
  • A struct does not automatically update copies already stored elsewhere.
  • An enum does not prevent bad transitions unless your graph checks them.
  • Switch on Enum does not run every case. It runs the matching case for that execution pulse.
  • An enum is not a Gameplay Tag. Tags are better for hierarchical labels and content-driven classification.
  • A struct is not a Data Table by itself. A Data Table is many rows that share a struct shape.

The pattern everyone actually uses

For a door:

Enum EDoorState:
    Closed, Opening, Open, Closing

Variable DoorState = Closed

Interact:
-> Switch on EDoorState
   Closed:
       Set DoorState = Opening
       Play open timeline
   Open:
       Set DoorState = Closing
       Play close timeline
   Opening / Closing:
       do nothing

Timeline Finished:
-> if opening finished: Set DoorState = Open
-> if closing finished: Set DoorState = Closed

For inventory:

Struct FInventoryItem:
    ItemId
    DisplayName
    Count

Array InventoryItems

AddItem(NewItem):
-> Find existing entry by ItemId
-> if found:
       copy existing struct
       Set Members Count = Count + NewItem.Count
       Set Array Element
   else:
       Add NewItem

Lookalikes - which one do I want?

Tool Use when Watch out
Struct Related fields should travel together as one value. It is copied unless you set the owner back.
Enum One value should be chosen from a fixed list. It does not enforce transitions by itself.
Switch on Enum Execution should branch by a named enum value. Keep every case intentional.
Boolean There are only two states and they cannot contradict another value. Several booleans often create impossible combinations.
Gameplay Tag Content needs labels such as Weapon.Rifle or Surface.Stone. Tags classify; they do not give switch pins by default.
Data Table row Many entries share one struct shape. The table is data storage, not per-frame gameplay state.

Rule of thumb: struct for a record, enum for a mode, switch for behavior by mode.

Going deeper