Actor classes
Gameplay in Vilanel is built from actor classes. An actor class is a single
.vactor asset that describes everything about an actor. A game is made of these
classes, placed in levels or spawned while the game runs.
What a class contains
| Parent class | A built-in class, a class from the project's C++ module, or another .vactor. |
| Components | A tree of parts such as meshes, colliders, cameras and lights. |
| Variables | Typed values with defaults. Each placed copy can override them. |
| Event graph | The class's behaviour: its events and what they do. |
| Construction script | A graph that runs when a copy is created, before the game starts. |
| Functions | Reusable graphs with their own local variables. |
A .vactor whose parent is the built-in Character class inherits all of the
character's movement and adds its own behaviour on top.
Built-in classes
- Pawn: anything a player or an AI can control.
- Character: a pawn that walks, runs, jumps, crouches and goes prone. It accelerates and brakes smoothly, and its camera sits on a spring arm that moves in when a wall is behind it.
- PlayerController: represents the player's control over a pawn.
- GameMode: the rules of a level, including which pawn and controller class each player gets.
Classes read their settings directly from their components, so changing a value in the editor while the game is running takes effect immediately.
Inheritance
When a class inherits from another .vactor, both classes' graphs run: the
parent's first, then the child's. A subclass can also override individual
inherited components without copying the whole component tree.
Events and functions
Events can wait. A Delay node pauses an event and resumes it later while the rest of the game keeps running. Functions cannot wait, because they have to return their result in the same frame, so the compiler rejects a Delay inside a function. Custom events are functions that are allowed to wait.
Functions can also be pure, meaning they have no execution wire and simply return a value. A pure node is evaluated once, where it is first used, and other nodes reuse that result. If the first use is in a branch that does not run, the other nodes see an old value, so avoid sharing one pure node between branches that run at different times.
Construction scripts
The construction script runs every time a copy of the class is created, which can happen more than once. It should set values rather than add to them, so that running it twice gives the same result.
Spawning
Actors are spawned by class name, so a spawned actor can be rebuilt just like a placed one, for example after a C++ module reloads. Keep a reference to the actor's entity rather than a pointer to the actor object.
Networking
Network roles and replicated variables are part of the actor class. Replicated variables are sent to clients automatically, and an actor can check whether it has authority before doing something that only the server should do.
Related
- Node graph: the editor the graphs are built in
- C++ modules and hot reload: classes written in C++
- Scene and entities: how placed copies are stored