Skip to content
Tutorials Center
My learning

Topics

Lesson 17 of 38 ยท Blueprints

Blueprint Variables, Functions, Macros and Custom Events

Master Blueprint building blocks: variable types and Instance Editable, arrays, structs and enums, functions versus macros versus custom events, timelines and delays.

Once you can connect nodes, the next step is organizing your logic: storing state in variables, reusing steps in functions and macros, and reacting to things with events. This lesson explains each, when to use which, and the traps beginners fall into.

Unreal Engine cannot run in your browser. Editor steps are in words; the Python stand-ins model the same ideas.

Variables

Create a variable in My Blueprint > Variables > +. Choose a type and name it. Each has a Default Value you set after compiling. Common types:

Type Notes
Boolean true or false (red)
Integer / Float whole or decimal numbers
String / Name / Text Text is for display and localization; Name is cheap and case-insensitive; String is for general use
Vector / Rotator / Transform 3D math values
Object / Actor reference points to another object
Class reference points to a class (to spawn it)
Enum a fixed list of choices
Struct a bundle of fields
Array / Set / Map collections (the icon next to the type)

Two checkboxes matter in Details:

  • Instance Editable (eye icon): you can change the value per actor placed in the level.
  • Expose on Spawn: the value becomes an input pin on Spawn Actor from Class.

Name Booleans like questions (bIsOpen) and keep names descriptive. Set variables with the Set node and read with Get; hold Alt and click a variable to drop a Set node, and Ctrl to drop a Get.

Python Stand-in: variables, defaults and instance values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Arrays, structs and enums

  • Array: an ordered list. Nodes: Add, Remove Index, Get (a copy), Length, Contains, For Each Loop, Shuffle.
  • Map: key to value, for example an item name to a count.
  • Enum: create one in the Content Browser (Blueprints > Enumeration), for example EDoorState { Closed, Opening, Open }. Use a Switch on Enum node to branch.
  • Struct: create one (Blueprints > Structure) such as FItemData { Name, Weight, Icon } and keep arrays of them.

Functions

A Function has inputs, outputs and its own graph with a single entry. Use functions for logic you call from several places, and to keep the Event Graph short. Functions:

  • run in one frame (no Delay or latent nodes);
  • can have local variables;
  • can be Pure (no execution pins, no side effects, like GetHealthPercent), which gives you a compact green node;
  • can be overridden in child Blueprints, and made static in function libraries.

Create one with My Blueprint > Functions > +, then add input/output parameters in Details.

Macros

A Macro is a reusable chunk of graph that is expanded in place wherever it is used. It can have several execution outputs and can contain latent nodes like Delay. Use macros for control-flow patterns (a custom loop, "do N times") and functions for everything else.

Events and Custom Events

An Event is an entry point. Beyond built-ins (BeginPlay, Tick, overlaps, input) you create Custom Events: right-click the Event Graph > Add Custom Event. A custom event:

  • can take inputs;
  • can be called from anywhere in the same Blueprint, or from other Blueprints once you have a reference;
  • can contain Delay and other latent nodes (functions cannot);
  • can be replicated (a Run on Server or Multicast event in multiplayer).
flowchart LR
  I["Input: Interact"] --> C["Custom Event: ToggleDoor"]
  B["Overlap: Auto door"] --> C
  C --> A["Play door animation"]

Several triggers can call one custom event.

Python Stand-in: function, event and a pure helper

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Time: Delay, Timer and Timeline

  • Delay: waits N seconds, then continues (event graph and macros only).
  • Set Timer by Event / by Function Name: calls an event repeatedly or once after a time; handles can be cleared. Better than Tick for "every second" work.
  • Timeline: a node with curves for values over time (open a door over 1.5 s, fade a light). Double-click it to edit the float, vector or color tracks, and use Play, Reverse, Play from Start inputs and the Update and Finished outputs. Combine with Lerp to move a door between two transforms.

Flow control cheat sheet

  • Branch (if / else).
  • Sequence: run outputs in order (Then 0, Then 1...).
  • For Each Loop and For Loop: iterate an array or a range; Break exits early.
  • Do Once / Do N / Gate / FlipFlop: tiny state machines for one-time or toggle behavior.
  • Select node: choose a value without branching.

An infinite loop (a While Loop whose condition never becomes false) freezes the editor and Unreal reports "Infinite loop detected". Always make sure the loop changes what it checks.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does Instance Editable allow?

    Instance Editable shows the variable in the Details panel of each instance.
  2. 2. Where can you use a Delay node?

    Functions cannot contain latent nodes; event graphs, custom events and macros can.
  3. 3. When should you prefer a Timeline?

    Timelines drive curves over time and are ideal with Lerp for movement and fades.
  4. 4. What is a pure function?

    Pure functions only compute and return a value, like a green node.

Summary

  • Variables have types, defaults, Instance Editable and Expose on Spawn; collections are Arrays, Sets and Maps.
  • Functions are single-frame and reusable, macros expand in place, and custom events can wait with Delay.
  • Use timers and timelines instead of heavy Tick work.
  • Avoid infinite loops and keep names meaningful.

Next: Blueprint Communication