Port your project to SpatialOS
2. Modify and build your project
Before you open your project in the Editor you need to:
- Add the SpatialGDK module to your project
- Build your project using Visual Studio
Step 1: Add the SpatialGDK module to your project
To use the GDK and SpatialOS networking, you must add the SpatialGDK module to your project.
- In File Explorer, navigate to
\<ProjectRoot>\<GameRoot>\Source\<YourProject>\
. - Open the
<YourProject>.build.cs
file in a code editor and add add"SpatialGDK"
toPublicDependencyModuleNames
.
For example:
PublicDependencyModuleNames.AddRange(
new string[] {
"Core",
"CoreUObject",
"Engine",
"OnlineSubsystem",
"OnlineSubsystemUtils",
"AssetRegistry",
"AIModule",
"GameplayTasks",
"SpatialGDK",
}
);
Step 2: Build your project
Set up your Unreal project to work with the GDK Unreal Engine fork, which you cloned and installed in the Before you start section.
To do this:
- In File Explorer, navigate to
<ProjectRoot>\<GameRoot>
. - Right-click your
<YourProject>.uproject
file and select Switch Unreal Engine version. - Select the path to the Unreal Engine fork you cloned earlier. This associates your project with the Unreal Engine fork and automatically generates a Visual Studio solution file for your project called
<YourProject.sln>
- In the same directory, double-click
<YourProject>
.sln to open it with Visual Studio. - On the Visual Studio toolbar, set your Solution configuration to Development Editor.
Image: The Visual Studio toolbar, with the Development Editor Solution configuration highlighted in red. - In the Solution Explorer window, right-click on
<YourProject>
and select Build.
Step 3: Modify Unreal classes for GDK compatibility
You must modify your GameInstance
class to work with the GDK.
Make your GameInstance
inherit from SpatialGameInstance
.
If you have not made a
GameInstance
for your game and are still using the defaultGameInstance
, you must either create a Blueprint or a nativeGameInstance
class now. Remember to configure yourProject Settings
to use this newGameInstance
by default, under Project Settings > Project Maps and Modes > Game Instance > Game Instance Class.If your game’s
GameInstance
is a C++ class, locate its header file and add the following#include
:"SpatialGameInstance.h"
For example:
#include "CoreMinimal.h"
#include "SpatialGameInstance.h"
#include "YourProjectGameInstance.generated.h"
Then, under UCLASS()
, change the parent class from UGameInstance
to USpatialGameInstance
:
For example:
UCLASS()
class YOURPROJECT_API UYourProjectGameInstance : public USpatialGameInstance
{
GENERATED_BODY()
};
If your
GameInstance
is a Blueprint class, you need to open and edit it in the Blueprint Editor:- From the Blueprint Editor toolbar, navigate to the Class Settings. In Class Options set the Parent Class to
SpatialGameInstance
.
- From the Blueprint Editor toolbar, navigate to the Class Settings. In Class Options set the Parent Class to
Image: The Blueprint class settings screen
Step 4: Modify your project to support SpatialOS cloud deployments
Before you launch a cloud deployment, you need to make sure that spatial
directory gets cooked when you build your workers. To do this, open DefaultGame.ini (located in
[/Script/UnrealEd.ProjectPackagingSettings]
+DirectoriesToAlwaysCook=(Path="Spatial")
#### > Next: 3. Launch a local deployment
————
2019-07-16 Page updated with editorial review.