When i add an id as friend, it adds successfully but when i try to get friends list, the unity console gives an error - MenuController.DisplayFriends (System.Collections.Generic.List`1[T] friendsCache)
What to do?
Would you please share the code that's causing this error? A complete reproduce step would be helpful.
first script:
void DisplayFriends(List<PlayFab.ClientModels.FriendInfo> friendsCache) { loadingPanel.SetActive(false); foreach(PlayFab.ClientModels.FriendInfo f in friendsCache) { fl.Instantiate(f.TitleDisplayName, f.Profile.Statistics[6].Value, myFriendListing, myFriendsScrollView, f.Profile.Statistics[1].Value); } } List<FriendInfo> _friends = null;
the refrenced script (fl)
public void Instantiate(string name, int medals, GameObject listing, Transform scrollView, int avatar) { GameObject mf = Instantiate(listing, scrollView); Text Name = mf.transform.GetChild(0).GetComponent<Text>(); Name.text = name; Image Avatar = mf.transform.GetChild(1).GetComponent<Image>(); Avatar.sprite = av.AllAvatars[avatar]; Text Medals = mf.transform.GetChild(3).GetComponent<Text>(); Medals.text = medals.ToString(); }
The error is on first script
MenuController.DisplayFriends (System.Collections.Generic.List`1[T] friendsCache)
The error when I call the function DisplayFreinds() is
It stopped giving that error for a while but after sometime it gave same error even if i have not called the statistics
That shouldn't be a error from PlayFab , you may need to debug your code to find the root cause.
I am using this code for getting
void GetFriends() { loadingPanel.SetActive(true); PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest { IncludeSteamFriends = false, IncludeFacebookFriends = false, XboxToken = null, ProfileConstraints = new PlayerProfileViewConstraints() { ShowStatistics = true, ShowDisplayName = true } }, result => { _friends = result.Friends; DisplayFriends(_friends); // triggers your UI }, DisplayPlayFabError) ; }
And this for displaying
void DisplayFriends(List<PlayFab.ClientModels.FriendInfo> friendsCache) { loadingPanel.SetActive(false); foreach(FriendInfo f in friendsCache) { GameObject mf = Instantiate(myFriendListing, myFriendsScrollView); string tdn = f.TitleDisplayName; fl.NameText.text = tdn; } }
@Tanmay KulkarniI've created a test account (Displayname : CitrusYanTest) in your title and added "ArnavPoar" as Friend. When debugging the code your provided, I get the following:
The "f.TitleDisplayname" field is correct, hence this may not be a issue from PlayFab side, you should probably debug your code to find what's really going on.
This is the code I used for testing:
using PlayFab; using UnityEngine; using PlayFab.ClientModels; public class test : MonoBehaviour { // Start is called before the first frame update void Start() { PlayFabSettings.TitleId = "96638"; PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest { CreateAccount = false, CustomId = "CitrusYanTest", TitleId = "96638" }, OnLoginSuccessLocal, null); } private void OnLoginSuccessLocal(LoginResult result) { Debug.Log("login success"); GetFriends(); } private void GetFriends() { PlayFabClientAPI.GetFriendsList(new GetFriendsListRequest { IncludeSteamFriends = false, IncludeFacebookFriends = false, XboxToken = null, ProfileConstraints = new PlayerProfileViewConstraints() { ShowStatistics = true, ShowDisplayName = true } }, result => { foreach (FriendInfo f in result.Friends) { string tdn = f.TitleDisplayName; } Debug.Log("friend display name:" + result.Friends[0].TitleDisplayName); }, OnErrorShared); } private static void OnErrorShared(PlayFabError error) { Debug.Log(error.GenerateErrorReport()); } }
This showed the same error
Would you please add a breakpoint into your code and check the full result from the GetFriendsList request? Moreover, a fiddler trace would also be helpful.
I would really thank you.
You have solved the problem. I used your code once and it worked, but I am unable to find that what I was doing wrong?
I would really rate PlayFab 5 stars for best community support.
Thank You So Much!
Glad it helped, you may need to debug your code step by step to find the root cause
2 People are following this question.