Skip to content

Commit 7f09015

Browse files
committed
Migrate Unreal tutorial
1 parent 4a9991a commit 7f09015

File tree

10 files changed

+3714
-1156
lines changed

10 files changed

+3714
-1156
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Overview
3+
---
4+
5+
# Unreal Tutorial - Overview
6+
7+
Need help with the tutorial or CLI commands? [Join our Discord server](https://discord.gg/spacetimedb)!
8+
9+
In this tutorial you'll learn how to build a small-scoped massive multiplayer online action game in Unreal, from scratch, using SpacetimeDB. Although, the game we're going to build is small in scope, it'll scale to hundreds of players and will help you get acquainted with all the features and best practices of SpacetimeDB, while building [a fun little game](https://github.com/ClockworkLabs/Blackholio).
10+
11+
By the end, you should have a basic understanding of what SpacetimeDB offers for developers making multiplayer games.
12+
13+
The game is inspired by [agar.io](https://agar.io), but SpacetimeDB themed with some fun twists. If you're not familiar [agar.io](https://agar.io), it's a web game in which you and hundreds of other players compete to cultivate mass to become the largest cell in the Petri dish.
14+
15+
Our game, called [Blackhol.io](https://github.com/clockworklabs/SpacetimeDB/tree/master/demo/Blackholio), will be similar but space themed. It should give you a great idea of the types of games you can develop easily with SpacetimeDB.
16+
17+
This tutorial assumes that you have a basic understanding of the Unreal Engine, using a command line terminal and programming in C++. We'll give you some CLI commands to execute. If you are using Windows, we recommend using Git Bash or PowerShell. For Mac, we recommend Terminal.
18+
19+
We’ll keep things intentionally simple: a single “Game Manager” class, minimal error handling, and hardcoded settings where convenient. This makes the SDK flow easy to see. For production, prefer Unreal’s Subsystems, move secrets out of code, follow best practices, and add proper logging/retry.
20+
21+
SpacetimeDB supports Unreal Engine version `5.6`. This tutorial has been tested only with that version.
22+
23+
This tutorial is written for C++, but the SpacetimeDB Unreal client SDK also supports Blueprints! Stay tuned for a Blueprint-based tutorial.
24+
25+
Please file an issue [here](https://github.com/clockworklabs/SpacetimeDB/issues) if you encounter an issue with a specific Unreal version, but please be aware that the SpacetimeDB team is unable to offer support for issues related to versions of Unreal prior to `5.6`.
26+
27+
## Blackhol.io Tutorial - Basic Multiplayer
28+
29+
First you'll get started with the core client/server setup. For part 2, you'll be able to choose between [Rust](/docs/modules/rust) or [C#](/docs/modules/c-sharp) for your server module language:
30+
31+
- [Part 1 - Setup](/docs/unreal/part-1)
32+
- [Part 2 - Connecting to SpacetimeDB](/docs/unreal/part-2)
33+
- [Part 3 - Gameplay](/docs/unreal/part-3)
34+
- [Part 4 - Moving and Colliding](/docs/unreal/part-4)
35+
36+
## Blackhol.io Tutorial - Advanced
37+
38+
If you already have a good understanding of the SpacetimeDB client and server, check out our completed tutorial project!
39+
40+
[https://github.com/clockworklabs/SpacetimeDB/tree/master/demo/Blackholio](https://github.com/clockworklabs/SpacetimeDB/tree/master/demo/Blackholio)
Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: 1 - Setup
3+
---
4+
5+
# Unreal Tutorial - Part 1 - Setup
6+
7+
Need help with the tutorial? [Join our Discord server](https://discord.gg/spacetimedb)!
8+
9+
> A completed version of the game we'll create in this tutorial is available at:
10+
>
11+
> [https://github.com/clockworklabs/SpacetimeDB/tree/master/demo/Blackholio](https://github.com/clockworklabs/SpacetimeDB/tree/master/demo/Blackholio)
12+
13+
## Prepare Project Structure
14+
15+
:::note
16+
Ensure you have SpacetimeDB version >=1.4.0 installed to enable Unreal Engine code generation support.
17+
:::
18+
19+
This project is separated into two subdirectories;
20+
21+
1. Server (module) code
22+
2. Client code
23+
24+
First, we'll create a project root directory (you can choose the name):
25+
26+
```bash
27+
mkdir blackholio
28+
cd blackholio
29+
```
30+
31+
We'll start by populating the client directory.
32+
33+
## Setting up the Tutorial Unreal Project
34+
35+
In this section, we will guide you through the process of setting up a Unreal Project that will serve as the starting point for our tutorial. By the end of this section, you will have a basic Unreal project and be ready to implement the server functionality.
36+
37+
### Step 1: Create a Blank Unreal Project
38+
39+
SpacetimeDB supports Unreal version `5.6`. See [the overview](.) for more information on specific supported versions.
40+
41+
Launch Unreal 5.6 and create a new project by selecting Games from the Unreal Project Browser.
42+
43+
:::warning
44+
Select the **Blank** template and in **Project Defaults** select **C++**.
45+
:::
46+
For **Project Name** use `client_unreal`.
47+
For **Project Location**, use your `blackholio` directory (created in the previous step).
48+
49+
Click **Create** to generate the blank project.
50+
51+
![Create Blank Project](https://tmp-unreal-engine-tutorial-images.nyc3.digitaloceanspaces.com/part-1-01-create-project.png)
52+
53+
### Import the SpacetimeDB Unreal SDK
54+
55+
While the SpacetimeDB Unreal client SDK is in preview releases, it can only be installed from GitHub:
56+
57+
> [https://github.com/clockworklabs/SpacetimeDB/tree/master/sdks/unreal/src](https://github.com/clockworklabs/SpacetimeDB/tree/master/sdks/unreal/src)
58+
59+
Once the SDK is stabilized, we'll find a more ergonomic way to distribute it.
60+
61+
:::note
62+
Before beginning make sure to close the Unreal project and IDE.
63+
:::
64+
65+
#### Installation steps
66+
67+
1. Navigate to your Unreal project directory and create a `Plugins` folder if it doesn’t already exist:
68+
69+
```bash
70+
cd client_unreal
71+
mkdir Plugins
72+
```
73+
74+
2. Download or clone the SDK from GitHub and copy the SpacetimeDbSdk folder into your new Plugins directory.
75+
- This should create `/client_unreal/Plugins/SpacetimeDbSdk`.
76+
3. In the root of the Unreal project, right click the client_unreal.uproject and select **Generate Visual Studio project files**. On Windows 11 you may need to expand **Show more options** to select the generate option.
77+
78+
![Generate project files](https://tmp-unreal-engine-tutorial-images.nyc3.digitaloceanspaces.com/part-1-02-01-generate-project.png)
79+
![Generate project files](https://tmp-unreal-engine-tutorial-images.nyc3.digitaloceanspaces.com/part-1-02-02-generate-project.png)
80+
81+
### Create the GameManager Actor
82+
83+
1. Open the `client_unreal` project in your IDE (Visual Studio or JetBrains Rider) and run the project to launch the Unreal Editor.
84+
- This will enable **Live Coding**, making the workflow a bit smoother.
85+
- Unreal will prompt you to build the `SpacetimeDbSdk` plugin. Do so.
86+
2. Open **Tools -> New C++ Class** in the top menu, select **Actor** as the parent and click **Next**
87+
3. Select **Public** Class Type
88+
4. Name the class `GameManager`.
89+
90+
The `GameManager` class will be where we will put the high level initialization and coordination logic for our game.
91+
92+
> **Note:** In a production Unreal project, you would typically implement this logic in a Subsystem. For simplicity, this tutorial uses a singleton actor.
93+
94+
### Set Up the Level
95+
96+
Set up the empty level, add the new `GameManager` to the level, and add lighting.
97+
98+
1. **Create a new level**
99+
- Open **File -> New Level** in the top menu, select **Empty Level**, and click **Create**.
100+
- Save the level and name it `Blackholio`.
101+
102+
2. **Create a GameManager Blueprint**
103+
- In the **Content Drawer**, click **Add**, then select **Blueprint -> Blueprint Class**.
104+
- Expand **All Classes**, search for **GameManager**, highlight it, and click **Select**.
105+
- Name the blueprint `BP_GameManager`.
106+
107+
![Pick Parent Class](https://tmp-unreal-engine-tutorial-images.nyc3.digitaloceanspaces.com/part-1-03-create-blueprint.png)
108+
109+
3. **Update Maps & Modes**
110+
- Open **Edit -> Project Settings** in the top menu, then select **Project -> Maps & Modes** on the left.
111+
- Set **Editor Startup Map** to `Blackholio`.
112+
- Set **Game Default Map** to `Blackholio`.
113+
114+
4. **Add to the Level**
115+
- Drag the `BP_GameManager` blueprint from the **Content Drawer** into the scene view.
116+
117+
5. **Add a Directional Light**
118+
- Click **Add** in the top toolbar, then select **Lights -> Directional Light**.
119+
- Set **Rotation** to -105.0, -31.0, -14.0.
120+
121+
6. **Add a Post Process Volume**
122+
- Click **Add** in the top toolbar, then select **Volumes -> Post Process Volume**.
123+
- Enable and set **Exposure -> Exposure Compensation** to 0.0.
124+
- Enable and set **Exposure -> Min EV100** to 1.0.
125+
- Enable and set **Exposure -> Max EV100** to 1.0.
126+
- Enable **Post Process Volume Settings -> Infinite Extend (Unbounded)**.
127+
128+
### Add a Simple GameMode
129+
130+
Create a simple GameMode to tweak the startup settings and connect it to the World Settings.
131+
132+
1. **Create the C++ class**
133+
- Open **Tools -> New C++ Class** in the top menu, select **GameModeBase** as the parent, and click **Next**.
134+
- Select **Public** as the class type.
135+
- Name the class `BlackholioGameMode`.
136+
137+
2. **Create a GameMode Blueprint**
138+
- In the **Content Drawer**, click **Add**, then select **Blueprint -> Blueprint Class**.
139+
- Expand **All Classes**, search for `BlackholioGameMode`, highlight it, and click **Select**.
140+
- Name the blueprint `BP_BlackholioGameMode`.
141+
142+
3. **Update World Settings**
143+
- Open **Window -> World Settings** in the top menu.
144+
- Change **GameMode Override** from **None** to `BP_BlackholioGameMode`.
145+
- Save the level.
146+
147+
At this point, the foundation of the Unreal project is set up. Pressing Play will show a blank screen, but the game should start without errors. Next, we’ll create the SpacetimeDB server module so we have something to connect to.
148+
149+
### Create the Server Module
150+
151+
We've now got the very basics set up. In [part 2](part-2) you'll learn the basics of how to create a SpacetimeDB server module and how to connect to it from your client.

0 commit comments

Comments
 (0)