Skip to content
Loom0.1.0
Source

Reference › Language

Language basics

What a Loom source file is, and how Loom turns it into an asset.

Page
index
Agent tool
docs index

A Loom source file describes one asset: a Blueprint, an enum, a struct or an interface. A Blueprint’s source gives its parent class, where it is saved, and its members. Loom compiles it to the editor operations that build that Blueprint, and the editor plugin applies them, so what you get is an ordinary Blueprint asset that the editor can open.

Every example in this reference is compiled by Loom’s tests against the engine’s own classes, so each one compiles as shown. An example with no header line is compiled with blueprint Example : Actor at /Game/Example in front of it.

A source starts with its header line, then any use and implements lines. Everything else comes after them.

blueprint BP_Door : Actor at /Game/Door/BP_Door
The header · always first
use /Game/Libs/Stock_1_0
use · zero or more, one folder each
implements BPI_Interactable
implements BPI_Lockable
implements · zero or more, one interface each
// then variables, functions, events…
Everything else

The header line names the Blueprint, its parent class and the asset path it is saved at. It starts with blueprint, or editor blueprint for a Blueprint that only runs in the editor. use is covered in Using a folder, and implements in Implementing an interface.

An enum or a struct starts with enum or struct instead, and what it holds follows in braces; see Types. An interface starts with interface, covered below in Declaring an interface.

The parent decides what kind of Blueprint a source makes, and what it can hold. These are the common kinds; any class Blueprints can extend works as a parent.

Kind Parent you write What it adds Can’t have
Actor blueprint Members Actor, or any actor class such as Pawn or Character Components, and events such as BeginPlay Widgets
Widget blueprint Widgets UserWidget, or a widget class Placed widgets Components
Editor Blueprint editor blueprint Editor Blueprints A class that only runs in the editor, such as EditorUtilityObject The editor’s own classes and functions, and subsystems What its parent can’t have
Function library blueprint Function libraries BlueprintFunctionLibrary Functions any Blueprint can call Variables, dispatchers, events, components, widgets, implements, self
Any other class blueprint Members Any class Blueprints can extend, such as Object Nothing more Components, widgets

The header has to match the parent. A parent that only runs in the editor needs editor blueprint, and editor blueprint with a parent that runs in the game is refused. An editor utility widget is both an editor Blueprint and a widget.

The parent can be written by name, or by path when a name is ambiguous. The asset’s name must be the Blueprint’s name.

BP_Counter.lm
blueprint BP_Counter : /Script/Engine.Actor at /Game/Counter/BP_Counter

A path saved somewhere other than the Blueprint’s name is refused:

Refused
blueprint BP_Counter : Actor at /Game/Counter/BP_Other

error: …must be saved as…

Several files compiled together are one program. Each can use the others’ Blueprints, their variables, widgets and functions, whichever file declares them. Loom applies each Blueprint after the ones it uses.

One program · 2 files, compiled together

BP_Till.lm
blueprint BP_Till : Actor at /Game/Shop/BP_Till
var Total: int = 0
fn Ring(price: int) {
Total = Total + price
}
BP_Customer.lm
blueprint BP_Customer : Actor at /Game/Shop/BP_Customer
var Till: BP_Till
fn Buy() {
Till.Ring(5)
}

A few words start a statement or a value, so they are never names: break, continue, else, for, if, let, match, return, while, true, false, none, self and super.

Refused
var if: int

error: …if is a reserved word…

Every other word the language uses, such as var, fn, out or in, means something only where a source expects it. Anywhere else it is a name like any other:

var in: int
fn Total(out: int) -> int {
return out + in
}

A name in backticks is a name even when it is a reserved word or holds spaces, so a source can name any member, such as a function a Blueprint made in the editor calls Add Stock. self and super are the exception: they are always this object, so nothing can be declared with either.

var `if`: int
fn `Add Stock`(amount: int) {
`if` += amount
}
fn Restock() {
`Add Stock`(5)
}

A class, struct or enum written by its name, such as BP_Till or Vector2D, means:

  1. the one of that name in the source’s own folder, when there is one. Only that folder counts, not the folders inside it.
  2. Otherwise, the one under the first folder the source uses that has one.
  3. Otherwise, the only one of that name in the project.

Two of that name at any step is an error, which lists their paths. Writing a path instead of the name always means exactly that one. So in a project with a BP_Stock in two folders, a source elsewhere can’t use the name alone:

One program · 3 files, compiled together

BP_Stock.lm
blueprint BP_Stock : Actor at /Game/Stock/BP_Stock
BP_Stock.lm
blueprint BP_Stock : Actor at /Game/Old/BP_Stock
Refused
blueprint BP_Shop : Actor at /Game/Shop/BP_Shop
var Shelf: BP_Stock

error: …BP_Stock is ambiguous; write its path…

It can write the path, var Shelf: /Game/Stock/BP_Stock.BP_Stock_C, or use the folder.

use names a folder a source takes short names from, such as a shared library’s. It is how a project holds two versions of a library, the released one and the next, with each source saying which it means in one line, and moving to another version by changing that line:

One program · 3 files, compiled together

BP_Stock.lm
blueprint BP_Stock : Actor at /Game/Libs/Stock_1_0/BP_Stock
var Count: int = 0
BP_Stock.lm
blueprint BP_Stock : Actor at /Game/Libs/Stock_2_0/BP_Stock
var Count: int = 0
var Reserved: int = 0
BP_Shop.lm
blueprint BP_Shop : Actor at /Game/Shop/BP_Shop
use /Game/Libs/Stock_1_0
var Shelf: BP_Stock
  • use comes straight after the header, before the Blueprint’s other items, and a source may use several folders. When more than one has a type of the name, the first written wins.
  • A used folder holds the folders inside it too, such as a library’s UI/.
  • It covers classes, structs and enums alike.
  • It applies only to the source that says it.
  • What’s in the folder needn’t be built from sources in the program. A library installed in the project as built Blueprints is used the same way.

A folder with nothing under it is an error, so a mistyped folder or a version the project doesn’t have is caught rather than letting a name mean another version:

Refused
blueprint BP_Shop : Actor at /Game/Shop/BP_Shop
use /Game/Libs/Stock_3_0

error: …nothing a source can use is under /Game/Libs/Stock_3_0…

use takes a folder, not an asset:

Refused
blueprint BP_Shop : Actor at /Game/Shop/BP_Shop
use /Game/Libs/Stock_1_0/BP_Stock.BP_Stock_C

error: …use takes a folder…

implements names an interface the Blueprint implements, such as one of the project’s Blueprint Interfaces, as the Blueprint’s Class Settings list them. It comes after the header and any use, one interface to a line, each named as any class is. The Blueprint’s handlers implement the interface’s functions.

BP_Curve.lm
blueprint BP_Curve : Actor at /Game/Curves/BP_Curve
implements MovieSceneEasingFunction
implements /Script/DataflowSimulation.DataflowSimulationActor
on OnEvaluate(t: float) -> float {
return t * t
}

A Blueprint implements what its parent implements already, so it doesn’t name those again. Unreal would let it, but would replace the parent’s functions that return a value with empty ones.

One program · 2 files, compiled together

BP_Curve.lm
blueprint BP_Curve : Actor at /Game/Curves/BP_Curve
implements MovieSceneEasingFunction
Refused
blueprint BP_Steep : BP_Curve at /Game/Curves/BP_Steep
implements MovieSceneEasingFunction

error: …already implements MovieSceneEasingFunction…

Only an interface can be implemented, once, and one that Blueprints can’t implement is refused:

Refusedeach row on its own
blueprint BP_Curve : Actor at /Game/Curves/BP_Curve
implements Actor

…Actor is not an interface…

implements MovieSceneEasingFunction
implements MovieSceneEasingFunction

…MovieSceneEasingFunction is implemented twice…

implements VisualLoggerDebugSnapshotInterface

…an interface a Blueprint cannot implement…

A Blueprint Interface has a source file of its own. The source is the interface alone: its name, the asset path it is saved at, then its functions in braces, one on each line, each a signature with no body. A // comment above a function becomes its tooltip.

One program · 2 files, compiled together

BPI_Usable.lm
// Something a player can use.
interface BPI_Usable at /Game/Interfaces/BPI_Usable {
fn Use(by: Actor)
fn CanUse(by: Actor) -> bool
}
BP_Door.lm
blueprint BP_Door : Actor at /Game/Door/BP_Door
implements BPI_Usable
var Open: bool = false
on Use(by: Actor) {
Open = !Open
}
on CanUse(by: Actor) -> bool {
return true
}

A Blueprint implements it as it would any other interface. A function that returns nothing is handled as an event, and one that returns a value or has an out parameter as a function, whose handler sets each output by its name, as a function sets its own:

One program · 2 files, compiled together

BPI_Counter.lm
interface BPI_Counter at /Game/Interfaces/BPI_Counter {
fn Count(of: string, out found: bool) -> int
}
BP_Shelf.lm
blueprint BP_Shelf : Actor at /Game/Shelf/BP_Shelf
implements BPI_Counter
var Stock: map<string, int> = {"wood": 3}
on Count(of: string, out found: bool) -> int {
found = Stock.Contains(of)
return if found { Stock[of] } else { 0 }
}

An interface declares at least one function, each once, and none takes a ref parameter:

Refusedeach row on its own
interface BPI_Usable at /Game/Interfaces/BPI_Usable {
fn Use(by: Actor)
fn Use(by: Pawn)
}

…Use is declared twice…

fn Use(count: ref int)
}

…is a ref, which an interface's function cannot take yet…

}

…BPI_Usable has no functions…

// starts a comment that runs to the end of the line. A run of comments directly above a variable, function or dispatcher is its description, which the editor shows as its tooltip. A // line with nothing after it starts a new paragraph.

// How many times Bump has run.
var Count: int = 0
// Adds one to Count.
//
// Nothing else changes.
fn Bump() {
Count = Count + 1
}