Sites

Menu

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.

  1. In File Explorer, navigate to \<ProjectRoot>\<GameRoot>\Source\<YourProject>\.
  2. Open the <YourProject>.build.cs file in a code editor and add add "SpatialGDK" to PublicDependencyModuleNames.

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:

  1. In File Explorer, navigate to <ProjectRoot>\<GameRoot>.
  2. Right-click your <YourProject>.uproject file and select Switch Unreal Engine version.
  3. 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>
  4. In the same directory, double-click <YourProject>.sln to open it with Visual Studio.
  5. On the Visual Studio toolbar, set your Solution configuration to Development Editor.
    GDK for Unreal Documentation
    Image: The Visual Studio toolbar, with the Development Editor Solution configuration highlighted in red.
  6. 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 default GameInstance, you must either create a Blueprint or a native GameInstance class now. Remember to configure your Project Settings to use this new GameInstance 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.

spatial game instance reparent
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 <GameRoot>\Config\DefaultGame.ini) configuration file in a text editor, and add the following two lines at the end of the file:

[/Script/UnrealEd.ProjectPackagingSettings]
+DirectoriesToAlwaysCook=(Path="Spatial")

#### > Next: 3. Launch a local deployment



————
2019-07-16 Page updated with editorial review.

Search results

Was this page helpful?

Thanks for letting us know!

Thanks for your feedback

Need more help? Ask on the forums