Kronos Matchmaking
Buy NowContact
  • About
    • Kronos LTS
    • Support
    • Accolades
  • Examples
    • Playable Demo
    • Sample Project
    • Example Content
  • Configuration
  • Testing & Debugging
  • Usage
    • Getting Started
    • Authentication
      • Authenticating Users
      • Customizing The Auth Widget
      • Creating Custom Auth Tasks
    • Matchmaking
      • Overview
      • Creating Matches
      • Starting Matchmaking
      • Canceling Matchmaking
      • Using Skill Ratings
      • Sending Match Invites
      • Joining Matches
      • Leaving Matches
    • Party
      • Overview
      • Creating Parties
      • Sending Party Invites
      • Joining Parties
      • Managing Party Players
      • Party Player Actors
      • Leaving Parties
    • Reservations
      • Overview
      • Using Reservations
      • The Host Reservation
      • Completing Reservations
    • Lobby
      • Overview
      • Lobby Setup
      • Set Players Ready
      • Lobby Player Data
      • Starting The Match
      • Updating Lobby Session
      • Leaving The Lobby
    • Widgets
  • Guides
    • Creating a Level Selector
    • Integrating with Lyra Game
    • Integrating with EIK
  • Advanced
    • Steam Sockets
    • Reconnect Parties
    • Custom Party Variables
    • Player Groups
  • Changelog
    • API Upgrades
    • Legacy
Powered by GitBook
On this page
  • Player Grouper Component
  • How To Setup
  • 1. Setting Up The Component
  • 2. Assigning Players To Groups
  • Using Player Groups
  • Player Group Events
  • Player Group Replication
  • What If There Is No Reservation Data?
  1. Advanced

Player Groups

PreviousCustom Party VariablesNextChangelog

Last updated 10 months ago

You may need to do certain things in your game that requires information on which players joined the game together. To make this process a bit easier, Kronos ships with a component that automatically assigns players into groups based on whether they joined the game together (as a party) or not.

The term Player Groups just refer to players who are assigned to the same group index by the KronosPlayerGrouperComponent. They are not the same as parties.

Player Grouper Component

The KronosPlayerGrouperComponent automatically assigns a group index to all players based on their reservation data. The group index is just a number that is unique to that group. You may be wondering what do reservations have to do with party information. When joining the game as a party, the party host requests a reservation for the entire party. So looking at the reservations we can tell which players belonged to the same party before they joined the game.

Players who joined the game together (as a party) will have the same group index. Using this you can essentially get the list of players who were in the same party before they joined the game. The component is fully replicated so clients can easily access this data as well.

How To Setup

Let's go over how to setup the KronosPlayerGrouperComponent.

1. Setting Up The Component

The component must be added to the GameState. Open up your game state blueprint (or class) and add the KronosPlayerGrouperComponent to it.

2. Assigning Players To Groups

Group indexes are assigned automatically for joining and leaving players if bAutoAssignGroupsToPlayers variable is enabled in the component. The exception to this is when the host used seamless travel to change maps (e.g. from lobby to game). Whether seamless traveling is used is set in the game mode.

When seamless traveling is used, the host must assign a group index to each seamless traveling player when they arrive on the new map.

For Blueprint projects, the game mode's OnSwapPlayerControllers event is a good place to handle group assignment for seamless traveling players. C++ projects can override the game mode's InitSeamlessTravelPlayer function directly.

#include "Components/KronosPlayerGrouperComponent.h"
#include "GameFramework/GameStateBase.h"
#include "GameFramework/PlayerState.h"
void AMyGameModeBase::InitSeamlessTravelPlayer(AController* NewController)
{
	Super::InitSeamlessTravelPlayer(NewController);

	// Make sure that the player state is valid.
	if (NewController->PlayerState)
	{
		// Get the player grouper component from the game state.
		UKronosPlayerGrouperComponent* PlayerGrouper = GameState->GetComponentByClass<UKronosPlayerGrouperComponent>();
		if (PlayerGrouper)
		{
			// Assign a group index to the player.
			const FUniqueNetIdRepl& PlayerId = NewController->PlayerState->GetUniqueId();
			PlayerGrouper->AssignGroupToPlayer(PlayerId);
		}
	}
}

Using Player Groups

Now that the component is set up, we can use the group index to get the list of players in a group. For example, lets print all player's names who are in the local player's group.

#include "Components/KronosPlayerGrouperComponent.h"
#include "KronosStatics.h"
#include "GameFramework/GameStateBase.h"
#include "GameFramework/PlayerState.h"
// Get the game state.
AGameStateBase* GameState = GetWorld()->GetGameState();
if (GameState)
{
	// Get the player grouper component.
	UKronosPlayerGrouperComponent* PlayerGrouper = GameState->GetComponentByClass<UKronosPlayerGrouperComponent>();
	if (PlayerGrouper)
	{
		// Loop through all players who are in the local player's group.
		const int32 LocalPlayerGroupIndex = PlayerGrouper->GetLocalPlayerGroupIndex();
		for (const FUniqueNetIdRepl& PlayerId : PlayerGrouper->GetAllPlayersInGroup(LocalPlayerGroupIndex))
		{
			// Get the player state from unique id.
			APlayerState* PlayerState = UKronosStatics::GetPlayerStateFromUniqueId(this, PlayerId);
			
			// PlayerState->GetPlayerName();
		}
	}
}

You can also use the GetGroupIndexOfPlayer node to access a player's group index via their PlayerId. You can get the player's PlayerId through their PlayerState.

Player Group Events

The KronosPlayerGrouperComponent also contains Blueprint assignable events for when a player is added or removed from a group. These are the OnPlayerAddedToGroup and OnPlayerRemovedFromGroup events respectively.

Player Group Replication

Group indexes are replicated to clients automatically. No setup work required. Please note that due to replication, group indexes should only ever be modified on server side!

What If There Is No Reservation Data?

There may be cases when no reservation data is available, for example when starting a map directly in the editor with multiple clients in listen server mode (without going through matchmaking).

When no reservation data is available the component can either assign all players into the same group, or assign all players into separate groups. The bUseSingleGroupIfNoReservationAvailable variable of the component dictates which mode to use.