Set Rich Presence #
The rich presence ext
(ExtRichPresence
) allows you to define custom presence data beyond simply “online” or “away”. For example, you may want a player’s friends to see their team’s current score, or allow players to set a custom away message.
Rich presence data can be set or updated by various components, allowing you to handle the data coming from the player, game server, or backend separately.
A user must have a basic presence set before adding a rich presence. If a basic presence is not set, attempting to add a rich presence will result in a Presence_PresenceNotFound
error.
Set from player client #
To set or update a rich presence from the player client, use the Presence API’s SetRichPresence()
SDK method for Unreal or Unity with the ExtRichPresencePlayerRequest
payload.
Player->PresenceApi().SetRichPresence(
const FPragma_Presence_ExtRichPresencePlayerRequest& RichPresenceRequest,
const FOnCompleteDelegate& OnComplete
);
Player.PresenceApi.SetRichPresence(
ExtRichPresencePlayerRequest richPresenceRequest,
CompleteDelegate onComplete
);
The Presence API’s SetRichPresence()
call invokes the Presence Plugin’s updateRichPresenceFromPlayer()
method and provides it with the ExtRichPresencePlayerRequest
payload. Use this method to validate data arriving from the player client and update ExtRichPresence
.
interface PresencePlugin {
suspend fun updateRichPresenceFromPlayer(
socialId: SocialId,
gameShardId: GameShardId,
currentPresence: Presence?,
requestExt: ExtRichPresencePlayerRequest
): ExtRichPresence
}
Set from game server #
To set or update a rich presence from the game server, use the Match API’s SetRichPresence()
SDK method with the ExtRichPresenceBackendRequest
payload.
Server->MatchApi().SetRichPresence(
const FString& PlayerId,
const FPragma_Presence_ExtRichPresenceBackendRequest& RichPresenceRequest,
const FOnCompleteDelegate& OnComplete
)
Server.MatchApi.SetRichPresence(
PragmaId playerId,
ExtRichPresenceBackendRequest richPresenceRequest,
CompleteDelegate onComplete
);
The Match API’s SetRichPresence()
call invokes the Presence Plugin’s updateRichPresenceFromBackend()
method and provides it with the ExtRichPresenceBackendRequest
payload. Use this method to create or update ExtRichPresence
.
interface PresencePlugin {
suspend fun updateRichPresenceFromBackend(
socialId: SocialId,
gameShardId: GameShardId,
currentPresence: Presence?,
requestExt: ExtRichPresenceBackendRequest
): ExtRichPresence
}
Set from backend #
To set or update a rich presence from a Pragma plugin or backend service, create an instance of the PresenceApi.kt
Kotlin class in a plugin or custom service.
private val presenceApi: PresenceApi = PresenceApi(service)
The PresenceApi class depends on theSocialBackendPartnerClientNodeService
. To use the PresenceApi in a custom service, addSocialBackendPartnerClientNodeService
as a dependency.
Then, call the PresenceApi class’s setRichPresence()
method with the player ID of the player whose presence to update and the ExtRichPresenceBackendRequest
payload:
class PresenceApi(
private val service: Service,
) {
suspend fun setRichPresence(
playerId: PlayerId,
richPresenceRequest: ExtRichPresenceBackendRequest
)
}
The setRichPresence()
method on the PresenceApi class invokes the Presence Plugin’s updateRichPresenceFromBackend()
method, as shown in the Set from game server section above.
Set both basic and rich presence #
A player client can set a basic presence and a rich presence at the same time using the Presence API’s SetPresence
with a basic presence value and an ExtRichPresencePlayerRequest
payload. If the user does not currently have a basic or rich presence status, SetPresence
creates one. Otherwise, the call updates the current presence values.
Player->PresenceApi().SetPresence(
EBasicPresence,
FPragma_Presence_ExtRichPresencePlayerRequest,
FOnCompleteDelegate
)
Player.PresenceApi.SetPresence(
BasicPresence basicPresence,
ExtRichPresencePlayerRequest extRichPresenceRequest,
CompleteDelegate onComplete
)
The SetPresence
call invokes the Presence Plugin’s updateRichPresenceFromPlayer
method, as shown in the Set from player client section above.
Related events:
Related errors: