question

siddhirajrayate741 avatar image
siddhirajrayate741 asked

Null Reference Exception on GetPlayerProfileResult()

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;

}

apis
1 comment
10 |1200

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

siddhirajrayate741 avatar image siddhirajrayate741 commented ·

profils() = OnGetStats();

I changed profils() name to OnGetStats() After error has came

0 Likes 0 ·

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

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());
});

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.