Skip to main content

Querying presence information of other users

To retrieve the presence information of a user's friends, and to use the GetPresence function on FOnlineFriend, you must first query the presence information through IOnlinePresence.

caution

You will only be able to retrieve presence information from Epic Games friends who are also currently playing your game. This is a limitation imposed by Epic Games.

This limitation does not apply to friends shown in the friends list through delegated subsystems.

Querying for presence information

IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlinePresencePtr Presence = Subsystem->GetPresenceInterface();

TArray<TSharedRef<const FUniqueNetId>> UserIds;
// Fill UserIds with the list of user IDs you want to query presence
// information for (e.g. a list of the user's friend IDs).

Presence->QueryPresence(
*Identity->GetUniquePlayerId(0).Get(),
UserIds,
IOnlinePresence::FOnPresenceTaskCompleteDelegate::CreateLambda([](
const class FUniqueNetId &UserId,
const bool bWasSuccessful)
{
// Check bWasSuccessful.
}));

You can call QueryPresence again to refresh with the latest presence information. In addition, the OnPresenceReceived and OnPresenceArrayUpdated events will be fired when the presence information is refreshed through QueryPresence.

Reading presence information

Once you have queried presence information, you can retrieve it using GetCachedPresence. GetCachedPresenceForApp ignores its AppId parameter and returns the same presence information, as EOS does not support application-specific presence data.

IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlinePresencePtr Presence = Subsystem->GetPresenceInterface();

TSharedRef<const FUniqueNetId> UserIdToGetPresenceFor = /* ... */;
TSharedPtr<FOnlineUserPresence> PresenceInfo;

if (Presence->GetCachedPresence(*UserIdToGetPresenceFor, PresenceInfo) == EOnlineCachedResult::Success)
{
// Presence information was retrieved and is now available in PresenceInfo.
}

You can also use the GetPresence function FOnlineFriend once you have queried presence information for the first time, and it will be retrieved from the cache (with the same result as GetCachedPresence).