Getting Started #
This guide covers setting up and logging into the Pragma backend using either the Pragma Unreal SDK or Unity SDK.
Unreal #
Prerequisites:
Set up the Player Controller and Game Mode Base #
- Open your Unreal project.
- Create a new “Player Controller” C++ class named
MyPlayerController
. - Create a new “Game Mode Base” class named
TutorialGameMode
.
Set up the Player Controller files #
- Compile and run the Unreal editor from your IDE.
- Create a Blueprint class for
MyPlayerController
calledMyPlayerControllerBP
. - Create a Blueprint class for
TutorialGameMode C++
calledTutorialGameModeBP
. - Open
TutorialGameModeBP
and set the Player Controller Class toMyPlayerControllerBP
. - Set up the
MyPlayerController.h
header file.
- Set up the Player Subsystem in your Player Controller.
Implement LogIn and LogOut Exec Functions #
- Add login and logout methods and handlers to your Player Controller.
- Recompile your project.
Hook up player controller to a new level #
- Hook up the
TutorialGameModeBP
to your new level:- Right click in the Content panel, create a new Level, and open that level.
- In your Blueprint Project settings, set your GameMode to the
TutorialGameModeBP
.
Test #
Ensure Pragma Engine is running.
To test this functionality using the Unreal in-game console, call the exec function LogIn test01. This will call our LogIn()
function with the username test01, which is an account that exists by default in the platform. You should see Pragma – Logged in.
in your Unreal output log.
The test login method is disabled by default in production. It is called ‘unsafe’ because it has no password or other security measures and is intended only for development use.
To apply this functionality using Unreal Blueprints, create a button that calls yourLogIn()
orLogOut()
function when clicked, as well as an input field where a player can enter their username.
Unity #
Prerequisites:
Create a C# MonoBehavior class #
- Open your Unity project.
- Use the Project pane to create a Scripts folder within the Assets folder.
- Right-click in the Scripts folder and create a new C# script named
PragmaManager
.- When you create the script directly from Unity, the file is populated with a Unity MonoBehaviour class.
- 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();
}
}
Facilitate login and logout #
To create a Pragma login/logout flow for your Unity project, add the following methods to your PragmaManager
file:
public void LogIn()
{
Player.LogIn(Pragma.Account.IdProvider.Unsafe, "test01", HandleLoggedIn);
}
public void LogOut()
{
Player.LogOut(HandleLoggedOut);
}
private void HandleLoggedIn(Pragma.Result result)
{
if (result.IsFailure)
{
Debug.LogErrorFormat("Pragma -- Login failed: {0}", result.ErrorCode);
return;
}
Debug.Log("Pragma -- Logged in.");
}
private void HandleLoggedOut()
{
Debug.Log("Pragma -- Logged out.");
}
Link the login script to a button #
- Open your project in the Unity editor.
- Right click in an empty part of the Hierarchy pane on the left side, click Create Empty, and name the
GameObject
PragmaManager
. - Drag the
PragmaManager.cs
script onto thePragmaManager
GameObject
. - Right click in the Hierarchy pane and select UI then Button.
- Expand the Button object in the Hierarchy pane and select Text.
- In the Inspector pane, find the text box with the default text of Button. Rename it by typing Login.
- In the Hierarchy pane, click on the Button object.
- In the On Click (), select the + sign, and drag
PragmaManager
from the Hierarchy pane onto None (Object) in the Inspector pane. Click No Function and selectPragmaManager
, then Login().
Test #
In Unity, click play, then click the Login button to connect to your locally running Pragma Engine instance. If successful, you should see a Pragma -- Logged in.
message in the Unity console.
The Unsafe login method is disabled by default in production. It is ‘unsafe’ because it has no password or other security measures!
Once logged in, you can call other Pragma API calls like this: Player.Service Name.Action().