Unreal: Matchmaking #
This tutorial uses Unreal Engine 5.3 with Pragma Engine 0.4.0 to demonstrate integrating Pragma Engine party functionality with a third-party game engine. This guide assumes you are proficient with Unreal Editor.
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 MyPlayerController.h
header file and MyPlayerController.cpp
source file to implement matchmaking functionality.
Update SDK #
Because there were changes to the ext protos, re-run the update script command from your Unreal Plugins folder:
update-pragma-sdk.sh
Enter matchmaking #
Goal Allow players in a party to enter matchmaking.
Steps #
In
MyPlayerController.h
, declareEnterMatchmaking()
:public: UFUNCTION(Exec, BlueprintCallable, Category="Pragma") void EnterMatchmaking();
In
MyPlayerController.cpp
, defineEnterMatchmaking()
to enter the party into a matchmaking queue:void AMyPlayerController::EnterMatchmaking() { Player->PartyApi().EnterMatchmaking( UPragmaPartyApi::FOnCompleteDelegate::CreateWeakLambda( this, [this](const TPragmaResult<> Result) { if (Result.IsSuccessful()) { UE_LOG(LogTemp, Display, TEXT("MyGameClient -- Enter matchmaking success.")); } else { UE_LOG(LogTemp, Error, TEXT("MyGameClient -- Unable to enter matchmaking: %s"), *Result.GetErrorAsString()); } })); }
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’sisReady
value is automatically set totrue
when 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 Unreal provides an OnAddedToGameInstance
event that fires when a party is added to a game instance. We can use these events in Unreal to trigger handler functions for matchmaking and game instance updates. For now, our HandleOnAddedToGameInstance()
function simply print an Unreal log entry.
Steps #
In
MyPlayerController.h
, declareHandleOnAddedToGameInstance()
:private: void HandleOnAddedToGameInstance(const FPragmaGameInstance& GameInstance);
In
MyPlayerController.cpp
, defineHandleOnAddedToGame()
:void AMyPlayerController::HandleOnAddedToGameInstance( const FPragmaGameInstance& GameInstance) { UE_LOG(LogTemp, Display, TEXT("MyGameClient -- Game instance ID: %s"), *GameInstance.GetId()); }
In the
MyPlayerController.cpp
BeginPlay()
function, register ourHandleOnAddedToGame()
function with the appropriate event handler:Player->GameInstanceApi().OnAddedToGameInstance.AddUObject( this, &AMyPlayerController::HandleOnAddedToGameInstance);
Test matchmaking functionality #
To test this functionality using the Unreal in-game console:
Open two clients and log in as
test01
andtest02
.As
test01
, create a party and set the game mode toCasual
. Set a character.As
test02
, create a party and set the game mode toCasual
. Set a character.As
test01
, callEnterMatchmaking()
As
test02
, callEnterMatchmaking()
To apply this functionality using Unreal Blueprints, create an “Enter matchmaking” button that calls the EnterMatchmaking
function and populated a text box with the resulting game instance ID.
Upon successfully entering matchmaking, the Unreal output log should display a “Enter matchmaking success.” message for each player, as well as identical game instance IDs for each player.
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.