Hi
I am Woking on getting player statistics but it is giving NullReferenceException: Object reference not set to an instance of an object ProfileInfoController.profils (PlayFab.ClientModels.GetPlayerProfileResult result).
This is the code
public int TotalGames;
public void GetStats(int id)
{
var stats = new GetPlayerProfileRequest();
stats.PlayFabId = "id";
PlayFabClientAPI.GetPlayerProfile(stats, OnGetStats, OnError);
}
void OnGetStats(GetPlayerProfileResult result)
{
// from down line error is coming
TotalGames = result.PlayerProfile.Statistics[0].Value;
}
profils() = OnGetStats();
I changed profils() name to OnGetStats() After error has came
Answer by Gosen Gao · Jun 07 at 07:20 AM
To get player’s statistics with API GetPlayerProfile, parameter ProfileConstraints is required. You need to set ProfileConstraints.ShowStatistics to true. Please refer to the code bolow.
var stats = new GetPlayerProfileRequest(); stats.PlayFabId = result.PlayFabId; stats.ProfileConstraints = new PlayerProfileViewConstraints(); stats.ProfileConstraints.ShowStatistics = true; PlayFabClientAPI.GetPlayerProfile(stats, result => { TotalGames = result.PlayerProfile.Statistics[0].Value; Debug.Log(TotalGames); }, error => { Debug.Log(error.GenerateErrorReport()); });