question

superdoesthings avatar image
superdoesthings asked

Player Display Names Only Showing Mine

Hello, I am using Photon and PlayFab and have TextMeshPro text as the player name in the Photon player prefab, and in-game all the names and IDs are only showing mine. I know why this is happening, because it's getting the display name and ID sort of client-side for the currently authenticated user, but I'm wondering if there's a way to get it for each user then display each user's individual display name and ID. Here is my code:

 public class PlayerNameScript : MonoBehaviour
 {
     public TextMeshPro playername;
     private string displayName;
     void Start()
     {
         GetDisplayName();
         string playfabID = PlayFabSettings.staticPlayer.PlayFabId;
         Debug.Log("player " + PhotonNetwork.LocalPlayer.ActorNumber);
         playername.text = displayName + " | ID : " + playfabID;
     }
    
     // Update is called once per frame
     void Update()
     {
    
     }
    
     public void GetDisplayName()
     {
         PlayFabClientAPI.GetPlayerProfile(new GetPlayerProfileRequest(), OnGetPlayerProfileSuccess, OnGetPlayerProfileError);
     }
     private void OnGetPlayerProfileSuccess(GetPlayerProfileResult result)
     {
         displayName = result.PlayerProfile.DisplayName;
         Debug.Log("User Display Name: " + displayName);
     }
     private void OnGetPlayerProfileError(PlayFabError error)
     {
         Debug.LogError("GetPlayerProfile Error: " + error.ErrorMessage);
     }
 }
apis
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Neils Shi avatar image
Neils Shi answered

The GetPlayerProfile API allows you retrieve only one specific player’s display name via setting the request’s PlayFabId field. If PlayFabId is not set, it will always get current authenticated player’s profile (based on the session ticket). To display other player’s name, you will need to use Photon to sync the name.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.