Join a Game via a Party #

The steps in this guide represent a common game loop when a player bypasses matchmaking and creates a custom game instance, and then invites other players to join their party and game. Specifically, the steps in this guide are:

  1. A player creates a new game instance
  2. More players join the game instance player’s party
  3. Party players join the existing game instance

Step 1: Create a custom game instance #

To bypass the matchmaking service and create a custom game instance from the player client, use the Game Instance API Create() method. The method will invoke the Game Instance Plugin handlePlayerCreateRequest() method, which, by default, creates a game instance and adds the player.

The Create() method accepts the following data:

  • ExtPlayerCreateRequest: custom data about the new game instance

Unreal:

Player->GameInstanceApi()->Create(
  const FPragma_GameInstance_ExtPlayerCreateRequest& RequestExt, 
  const FGameInstanceIdDelegate& OnComplete
);

Unity:

Player.GameInstanceApi.Create(
  ExtPlayerCreateRequest requestExt, 
  GameInstanceIdDelegate onComplete
)

Result:

  • A new game instance is created with the custom ext data.
  • The player is added to the game instance.

Step 2: Add more players to a party #

Players can join an existing party using the party’s invite code. For example, a player may want to join a party with an invite code they received from a player via Discord.

As a party leader, obtain the invite code using the Party API’s GetInviteCode() method:

Player->PartyApi().GetPartyCache()->Party()->GetInviteCode();

Unity:

player.PartyApi.GetPartyCache.GetParty.InviteCode

As a player not in a party, join a specific party using the Party API JoinPartyWithInviteCode() method with the following data:

  • ExtPlayerJoinRequest: Use this payload to specify custom player data, such as a selected champion, to pass to the onAddPlayers method when a player is added to a party. This data will be stored on the ExtPartyPlayer payload
  • inviteCode: invite code obtained by the player joining the party

Unreal:

Player->PartyApi().JoinPartyWithInviteCode(
  const FPragma_Party_ExtPlayerJoinRequest& ExtPlayerJoinRequest,
  const FString& InviteCode,
  const TMap<FString, int>& GameServerZoneToPing,
  const FOnCompleteDelegate& OnComplete
);

Unity:

player.PartyApi.JoinPartyWithInviteCode(
  ExtPlayerJoinRequest extPlayerJoinRequest,
  string inviteCode,
  Dictionary<string, int> gameServerZoneToPing,
  CompleteDelegate onComplete
);

Result:

  • Player is added to the party

Step 3: Allow party players to join game instance #

Allow players to join #

When a player attempts to join a game instance, the Game Instance Plugin handlePlayerJoinRequest() method is invoked. By default, this method prevents the player from joining the game. To allow a player to join a game instance, override handlePlayerJoinRequest():

override suspend fun handlePlayerJoinRequest(
    gameInstanceSnapshot: GameInstance.GameInstance,
    requestingPlayerId: PlayerId,
    requestExt: ExtPlayerJoinGameInstanceRequest
) {
    gameInstanceSnapshot.addPlayer(requestingPlayerId)
}

Join a game instance #

As a player not in a game instance, directly join a specific game instance using the Game Instance API’s Join() method with the following data:

  • GameInstanceId
  • ExtPlayerJoinGameInstanceRequest

Unreal:

Player->GameInstanceApi()->Join(
  const FString& GameInstanceId, 
  const FPragma_GameInstance_ExtPlayerJoinGameInstanceRequest& RequestExt,
  const FOnCompleteDelegate& OnComplete
)

Unity:

Player.GameInstanceApi.Join(
  PragmaId gameInstanceId, 
  ExtPlayerJoinGameInstanceRequest requestExt,
  CompleteDelegate onComplete
)

Result: Player is added to the game instance