Skip to main content

Read the recent players list

EOS Online Framework provides the "recent players" functionality of the friends interface. It does this by storing a list of recently seen players in Player Data Storage.

You don't need to manually add recently seen players; the plugin will check what other players are seen in multiplayer matches and automatically add them to the recent players list.

You no longer need to call QueryRecentPlayers - the plugin automatically caches the recent players during login and keeps the list of recent players up-to-date.

Getting the recent players list

To get a list of recent players, call GetRecentPlayers:

TArray<TSharedRef<FOnlineRecentPlayer>> RecentPlayers;
if (Friends->GetRecentPlayers(*Identity->GetUniquePlayerId(0), TEXT(""), RecentPlayers))
{
for (const auto &RecentPlayer : RecentPlayers)
{
// Access the recent player via `RecentPlayer`.
}
}
else
{
// Recent players could not be read.
}

Receive notifications when recent players change

The plugin automatically keeps track of players that a local user has recently seen on multiplayer servers. Therefore, the recent players list can update by itself, and you'll need to listen for the OnRecentPlayersAdded event to know when it changes:

FDelegateHandle Handle = Friends->AddOnRecentPlayersAddedDelegate_Handle(
FOnRecentPlayersAddedDelegate::CreateUObject(this, &UMyClass::OnRecentPlayersChanged));
// You can use `Handle` later to call `Friends->ClearOnRecentPlayersAddedDelegate_Handle(Handle)`
// if you want to unregister the event handler.

// ...

void UMyClass::OnRecentPlayersChanged(
const FUniqueNetId& UserId,
const TArray<TSharedRef<FOnlineRecentPlayer>>& AddedPlayers)
{
// The recent players list has changed. AddedPlayers contains a list
// of the players that were added.
}