Unity: Matchmaking #
This tutorial uses Unity 2021.3 with Pragma Engine 0.5.0 to demonstrate integrating Pragma Engine party functionality with a third-party game engine. This guide assumes you are proficient with Unity.
We’ve previously built the party flow up until the point players enter matchmaking: players can create a new party, join a party with an invite code, and select their game mode and characters. In this tutorial, we’ll expand the PragmaManager.cs file to implement matchmaking functionality.
Update PragmaSDK for Unity #
Whenever you make changes to Pragma Engine or update the code, you’ll want to update the PragmaSDK Unity plugin folder. Re-run the update script command from your project’s root directory:
update-pragma-sdk.sh
Enter matchmaking #
Goal #
Allow parties to enter matchmaking using the WarmBodyMatchmaking plugin.
Steps #
In PragmaManager.cs, add an EnterMatchmaking() method:
public void EnterMatchmaking()
{
Player.PartyApi.EnterMatchmaking(result =>
{
if (result.IsSuccessful)
{
Debug.Log("Pragma -- Party entered matchmaking");
}
else
{
Debug.Log("Pragma -- Party could not enter matchmaking");
}
});
}
As long as the two players are in different parties and both parties are set to the same game mode, the WarmbodyMatchmakingPlugin will match the two parties, create a game instance, and send the two parties to the game instance.
Players cannot enter matchmaking without being in the “ready” state. A player’sisReadyvalue is automatically set totruewhen they make a character selection. See Make character selections.
Display game instance information #
Goal #
Alert a player that they have been added to a game instance. This will verify the matchmaking process has succeeded.
The Pragma SDK for Unity provides an OnAddedToGameInstance event that fires when a player has been added to a game instance. We can use this event to trigger a handler function for matchmaking and game instance updates. For now, our HandleOnAddedToGameInstance() function simply print a log entry.
Steps #
In
PragmaManager.cs, add aHandleOnAddedToGame()method:private void HandleOnAddedToGame(Pragma.Common.GameInstance.PragmaGameInstance gameInstance) { Debug.Log("Pragma -- Added to game instance ID: " + gameInstance.GetId().ToString()); }In the
PragmaManager.csAwake()function, register ourHandleOnAddedToGame()function with the appropriate event handler:Player.GameInstanceApi.OnAddedToGameInstance += HandleOnAddedToGame;
Next steps #
At this point, players can enter matchmaking and enter game instances with appropriate matches. Continue to the Social tutorial to learn how to implement sample friend and presence functionality in Pragma.