Reference › Language
Types
The types values can have, and how to write them.
- Page
- types
- Agent tool
- docs types
Plain types
Section titled “Plain types”bool, int, int64, float, string, name and text are the Blueprint types of the same
names. A float is a double, as Blueprint floats are. The built-ins list
each one with what converts to it.
var Alive: bool = truevar Lives: int = 3var Seed: int64 = 0var Speed: float = 2.5var Title: string = "Counter"var Tag: name = "wood"var Label: text = "Hello"Classes, structs and enums
Section titled “Classes, structs and enums”A class, a struct or an enum is written by its name, or by its path when the name is ambiguous.
Names says which one a name means, and how use picks among several.
var Target: Actorvar Where: Vector2Dvar Group: ETickingGroup = ETickingGroup.TG_PostPhysicsvar Other: /Script/Engine.ActorA variable of a class holds an object of that class, or none.
An enum’s value is held as a number from 0 to 255. int(value) gives the number, and
Enum(number) the value it stands for, whether the enum names that number or not.
var Group: ETickingGroup = ETickingGroup.TG_PostPhysics
fn Next() { Group = ETickingGroup(int(Group) + 1)}Declaring an enum
Section titled “Declaring an enum”An enum is an asset of its own, so it has a source file of its own, saved as the enum’s name beside the asset. The source is the enum alone: its name, the asset path it is saved at, then its values in braces, one on each line. Every source in the project can use it as it would any other.
One program · 2 files, compiled together
// What a worker holds.enum E_Tool at /Game/Types/E_Tool { Hammer // Cuts wood. Saw "Hand Saw" Chisel}blueprint BP_Worker : Actor at /Game/Workers/BP_Worker
editable var Holding: E_Tool = E_Tool.Hammer
fn Cuts() -> bool { return Holding == E_Tool.Saw}A value is written by its name, as E_Tool.Saw, and the editor shows its name too. A string after
the name is what the editor shows instead, such as in a dropdown in the Details panel. A //
comment above the enum or a value becomes its tooltip.
An enum has at least one value and at most 255, each listed once, and no two are shown alike:
enum E_Tool at /Game/Types/E_Tool { Saw Saw}…Saw is listed twice…
Saw Blade "Saw"}…Blade and Saw would both be shown as…
}…E_Tool has no values…
Declaring a struct
Section titled “Declaring a struct”A struct is an asset of its own too, with a source file of its own. The source is the struct
alone: its name, the asset path it is saved at, then its fields in braces, one on each line, each
a name and a type, as a variable’s. A field starts out zero, or at the value after =.
One program · 2 files, compiled together
// A place on the grid.struct S_Cell at /Game/Types/S_Cell { X: int // How far up. Y: int = 1 Visited: bool Next: array<Vector2D>}blueprint BP_Grid : Actor at /Game/Grid/BP_Grid
var Start: S_Cell = S_Cell(X: 2)
fn Up() -> S_Cell { return S_Cell(X: Start.X, Y: Start.Y + 1)}A struct is made, read and changed as any other, and a //
comment above the struct or a field becomes its tooltip. A struct has at least one field, each
declared once, and none of its fields is the struct itself:
struct S_Cell at /Game/Types/S_Cell { X: int X: float}…X is declared twice…
Next: S_Cell}…which would hold itself…
}…S_Cell has no fields…
Interfaces
Section titled “Interfaces”A variable of an interface holds an object that implements it, or none. A value of the
interface comes from a cast to it.
var Easing: MovieSceneEasingFunction
fn Pick(thing: Object) -> bool { Easing = cast(thing, MovieSceneEasingFunction) return Easing != none}Delegates
Section titled “Delegates”A delegate is a function and the object to call it on, which the engine calls later, as Set Timer
by Event does. Its type is named after its signature, what it passes the function:
TimerDynamicDelegate for Set Timer by Event’s, which C++ calls FTimerDynamicDelegate. A function
named where one is expected is a delegate to it.
A function takes and returns one as Blueprint allows, to pass it on:
var Ticks: int = 0
fn Count() { Ticks += 1}
fn Every(seconds: float, handler: TimerDynamicDelegate) { KismetSystemLibrary.K2_SetTimerDelegate(handler, seconds, true)}
fn Counter() -> TimerDynamicDelegate { return Count}
on ReceiveBeginPlay { Every(0.5, Count) Every(2.0, Counter())}A function of an interface takes and returns one too, and a dispatcher passes one as it passes anything else. Blueprint keeps no delegate anywhere else, and has no way to call one:
blueprint BP_Timer : Actor at /Game/Timers/BP_Timervar Handler: TimerDynamicDelegate…Blueprint has no delegate variables…
fn Count() {}
fn Start() { let handler: TimerDynamicDelegate = Count}…Blueprint has no delegate variables…
fn Run(handler: TimerDynamicDelegate) { handler()}…Blueprint cannot call a delegate…
Nor can a struct’s field be a delegate:
struct S_Timer at /Game/Types/S_Timer { Handler: TimerDynamicDelegate}error: …the struct editor refuses a delegate field…
Containers
Section titled “Containers”array<T>, set<T> and map<K, V> are Blueprint arrays, sets and maps. Blueprints have no
nested containers, so none of them can hold another.
var Scores: array<int>var Seen: set<name>var Stock: map<string, int>var Grid: array<array<int>>error: …no nested containers…
Classes as values
Section titled “Classes as values”class<T> holds a class that is T or a subclass of it.
var Kind: class<Actor> = /Script/Engine.ActorSoft references
Section titled “Soft references”soft<T> refers to an asset by its path without loading it, and soft<class<T>> does the same for
a class. load() loads what it refers to and waits for it, and valid() says whether it refers to
anything.
var Engine: soft<class<Actor>> = /Script/Engine.Actor
fn Spawnable() -> bool { return Engine.valid()}