Listening to player state
Get notified about changes in player sign-in status, player profile, ban status and metadata.
Player profile, ban status and metadata update around once an hour on average. If you need the latest information, use the GetPlayerInfo method instead. Note that ban restrictions will still be enforced immediately regardless of whether you retrieve the latest player state.
To listen to player state, in the scripts that would be reacting to changes in the state, invoke the AddPlayerStateChangeListener method in CoreServices and provide a reference that receives the changes in player state. The player state is provided in an AuthState instance. You can also retrieve the current state immediately by specifying requireInitialState to be true.
Example
private void HandlePlayerState(AuthState state)
{
if (!state.IsSignedIn)
{
// Handle the case where the player is not signed in
// e.g. show a sign-in UI or redirect to a sign-in scene
}
// Handle other player info as needed
}
// ... in another method
CoreServices.AddPlayerStateChangeListener(HandlePlayerState, requireInitialState: true);To remove the listener (save resources when not used), just invoke the RemovePlayerStateChangeListener method and provide a reference to the same callback that you passed to AddPlayerStateChangeListener. This means that your callback must be and not .
CoreServices.RemovePlayerStateChangeListener(HandlePlayerState);Last updated