|
| 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 | + |
| 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 | + |
| 79 | + |
| 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 | +  |
| 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