Your first project
The goal: a new Unreal project with a Rust actor that writes to the log when the game starts.
Creating the project
rusteal new MyGame --dir ~/Projects
rusteal new does everything a first build needs:
- creates the Unreal project in
~/Projects/MyGame, from the engine’s Blank template; - installs the Rusteal plugins into its
Plugins/; - writes the Rust workspace in
Rust/, with your game crate and aHelloActor; - runs the whole build pipeline: it builds the project with the Unreal Build Tool, generates the Rust bindings for your engine, builds the game crate and deploys the library.
The first build takes a while: it compiles the engine module and generates bindings for the whole engine API. The builds after it only compile your crate.
rusteal new does not run git init, but it writes a .gitignore that covers Unreal’s and Cargo’s build output, so the right files are picked up when you do.
The Rust code
The game crate is in Rust/my-game/. Its src/lib.rs declares the library and its modules:
#![allow(unused)]
fn main() {
rusteal_runtime::entry!();
mod hello;
}
entry!() is required once per library: it is the function the Unreal plugin calls when it loads the library. Every other file is a normal Rust module.
src/hello.rs declares the actor:
#![allow(unused)]
fn main() {
use bindings::prelude::*;
use rusteal_runtime::{uclass, uclass_impl};
#[uclass(parent = Actor)]
pub struct HelloActor {}
#[uclass_impl]
impl HelloActor {
#[ufunction(Override)]
fn receive_begin_play(&mut self) {
log::info!("[MyGame] Hello from Rust");
}
}
}
#[uclass(parent = Actor)]makesHelloActoran Unreal class whose parent isAActor.#[uclass_impl]marks the block where its Unreal functions are.#[ufunction(Override)]onreceive_begin_playimplements the engine’sReceiveBeginPlayevent, the one a Blueprint’s Event BeginPlay node implements.log::info!writes to the Output Log (see Logging).
In the editor
- Open
MyGame.uproject. - In the main menu, open Window > Place Actors.
- In the Place Actors panel, type
HelloActorin the search box. - Drag HelloActor from the panel into the level viewport.
- Press Play in the toolbar.
- Open the Output Log tab (Window > Output Log if it is not open).
The log shows:
LogRusteal: [MyGame] Hello from Rust
Screenshot: the Place Actors panel with HelloActor found by the search, and the Output Log showing the message. (images/getting_started/hello_actor.png)
Changing the code
Change the message in hello.rs, then build the crate again:
cd ~/Projects/MyGame
rusteal build
The editor reloads the library as soon as the build deploys it, without a restart, and shows a notification. Press Play again to see the new message. The iteration loop explains what a reload changes, and how rusteal watch builds on every save.
The flags of rusteal new
| Flag | What it does |
|---|---|
--dir <path> | The directory the project is created in (the current one by default). |
--template <name> | The template to start from, blank by default. See Templates. |
--variant <name> | The template’s variant. |
--no-build | Writes the project and stops; run rusteal build --all later. |