Set up the Unity SDK #
This guide covers setting up and integrating the Pragma Unity SDK. This includes downloading the Pragma SDK, integrating it into a Unity project, and initializing it.
Download the SDK and integrate it into your project #
From the Portal homepage, click the Unity SDK download button.
- In your Unity project, add a PragmaSDK directory under Assets in your project. Path:
.../<unity-project>/Assets/PragmaSDK/
. - Unzip the contents of the download and move all items into the
PragmaSDK
folder. - Add a
Pragma.json
file under theAssets
directory.
{
"backendAddress": "https://game.<game-title>.<studio-title>.cloud.pragmaengine.com",
"gameClientVersion": "DefaultGameClientVersion"
}
- Build the project.
- If the build fails with the following error:
Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included on the current platform. Only one assembly with the same name is allowed per platform. (Assets/PragmaSDK/plugins/Newtonsoft.Json-for-Unity-12.0.301/Plugins/Newtonsoft.Json Editor/Newtonsoft.Json.dll)
- Delete the
.../<unity-project>/Assets/PragmaSDK/plugins/Newtonsoft.Json-for-Unity-12.0.301
folder and theNewtonsoft.Json-for-Unity-12.0.301.meta
file.- Rebuild project.
Create a Pragma Manager class #
From your Unity project, use the Project pane to create a
Scripts
folder underAssets
.Under
Scripts
, create aC# script
and name itPragmaManager
.Replace the code with the following:
using Pragma; using UnityEngine; public class PragmaManager : MonoBehaviour { public Pragma.Player Player { get; private set; } private void Awake() { // The Pragma Runtime is automatically initialized on first retrieval. var runtime = Pragma.Runtime.Get(); // This returns the first Player if available, or creates it. The Runtime is the source of truth for Player objects. Player = runtime.Player(); } }
Details
Pragma.Runtime.Get()
creates and initializes the Pragma Runtime, which is the main entrypoint into Pragma. In this case we use it to set configuration and access the Player session.runtime.Player()
is a convenience accessor to get (or create) the first Player session.
Create a PragmaManager GameObject #
- In your Unity editor, right click in the Hierarchy pane, select Create Empty, and name the
GameObject
PragmaManager
. - Add the
PragmaManager.cs
script onto thePragmaManager
GameObject
.