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.
APIs for modifying the friends list only impact the cross-platform friends database and will not affect the local platform or Epic Games friends list. This includes actions such as sending and receiving invites, blocking and unblocking players and modifying recent players.
It is not possible to support modifying the local platform's friends list or Epic Games friends list programmatically, as the platform SDKs and EOS SDK do not expose this functionality.
Getting the recent players list
- C++
- Blueprints
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
- C++
- Blueprints
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.
}