Presence

Overview

AccelByte Presence services enable players to see what other players are doing. Presence services can show players if their friends are online or offline, and if they’re available to play together. We use WebSocket to ensure that a player’s presence status is updated in real-time. These services include two main features:

  • Set User Presence allows clients to set a player’s availability and activity. There are four availability status options: Offline, Available, Busy, and Invisible. Activity status is customizable and can include Playing Game A, In Lobby, In Match, or In Party Looking For Members.
  • Get Friend Presence allows clients to show players what their friends are doing. Clients can display a player’s availability and activity status to their friends, so that players can invite friends that aren’t busy to play together.

If the service is successful, when a client sets a player’s availability code and status the that status will be visible to that player’s friends.

Tutorials

Create a Status and View a Friend’s Status

A player’s presence can be set by a game, or by Player Portal or Launcher. This allows the player’s friends to see when the player is online and what they are doing.

// View Changed Friend’s Status
AccelByte::FRegistry::Lobby.SetUserPresenceNotifDelegate(THandler<FAccelByteModelsUsersPresenceNotice>::CreateLambda([](const FAccelByteModelsUsersPresenceNotice Result)
{
UE_LOG(LogTemp, Log, TEXT("Friend %s, Activity: %s | Availability: %s "), Result.UserID, Result.Activity, Result.Availability);
}
));
// Create/Change Status
AccelByte::FRegistry::Lobby.SetUserPresenceResponseDelegate(Api::Lobby::FSetUserPresenceResponse::CreateLambda([](FAccelByteModelsSetOnlineUsersResponse result)
{
UE_LOG(LogTemp, Log, TEXT("User Status Changed!"));
}));
FString UserActivity = TEXT("Playing Game");
AccelByte::FRegistry::Lobby.SendSetPresenceStatus(Availability::Busy, UserActivity);

Get a List of Friends’ Statuses

Players can also see a list of all of their friends’ statuses.

AccelByte::FRegistry::Lobby.SetGetAllUserPresenceResponseDelegate(Api::Lobby::FGetAllFriendsStatusResponse::CreateLambda([](FAccelByteModelsGetOnlineUsersResponse result)
{
for(int i = 0; i < Result.friendId.Num(); i++)
{
UE_LOG(LogTemp, Log, TEXT("Friend %s, Activity: %s | Availability: %s "), Result.friendId[i], Result.Activity[i], Result.Availability[i]);
}
}));
AccelByte::FRegistry::Lobby.SendGetOnlineUsersRequest();

Bulk Friends Presence

Retrieve player’s presence information in bulk. This will also count the number of users based on their presence status, such as online, busy, invisible, or offline. You can also set the countOnly parameter to true to fetch the count without fetching the users’ account data.

var userIds = new List<string>();
userIds.Add("123456789");
userIds.Add("987654321");
bool countOnly = false;
AccelBytePlugin.GetLobby().BulkGetUserPresence(userIds, result =>
{
if(!result.IsError)
{
foreach( var user in result.Value.data)
{
Debug.Log("UserId: " + user.userID + " | Availability: " + user.availability.ToString());
}
Debug.Log("User’s status count. Online: " + result.Value.online + " | Busy:" + result.Value.busy + " | Invisible:" + result.Value.invisible + " | Offline:" + result.Value.offline);
}
else
{
Debug.Log("Error: " + result.Error.Code + " | Message: " + result.Error.Message);
}
}, countOnly);
});

Related Concepts