question

Dihyan Fauzana Rosadi avatar image
Dihyan Fauzana Rosadi asked

GetDataCharacter have some "delay",

I'm having problem "delay" when i tried to Get data from the character.

I have 2 function in different class

public List<string> DataResult = new List<string>();

public List<string> GetDataCharacter(List<string>Keys)
        {
            PlayFabClientAPI.GetCharacterData(
                new GetCharacterDataRequest()
                {
                    CharacterId = charID,
                    Keys = Keys
                },
                (GetCharacterDataResult result) =>
                {
                    for (int i = 0; i < Keys.Count; i++)
                    {
                        DataResult.Add(result.Data[Keys[i]].Value);
                    }

                },
                (PlayFabError error) => 
                {
                    Debug.Log(error);
                }
                );


            return DataResult;
        }
public void GetData()
        {
            
            List<string> TestKeysData = new List<string>();
            TestKeysData.Add("Hair");
            TestKeysData.Add("Skin");
            TestKeysData.Add("Eyes");
	    _loginController.GetDataCharacter(TestKeysData);

            List<string> ResultData = _loginController.GetDataCharacter(TestKeysData);

            Debug.Log("count "+ _loginController.GetData(TestKeysData).Count);
	    //Debug "count 0"

            Debug.Log("count " + ResultData.Count);
            //Debug "count 0"

            StartCoroutine(GetDataCoroutine());
        }
IEnumerator GetDataCoroutine()
        {
            List<string> TestKeysData = new List<string>();
            TestKeysData.Add("Hair");
            TestKeysData.Add("Skin");
            TestKeysData.Add("Eyes");


            _loginController.GetDataCharacter(TestKeysData);


            yield return new WaitForSeconds(1);


            Debug.Log("Count " + _loginController.DataResult.Count);
	    //Debug "count 3"
        }

It's seems when try get data there is some "delay". Is there any solution so i can use without coroutine for WaitForSeconds?

,

Character Data
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

·
Made Wang avatar image
Made Wang answered

There is a delay because the method is asynchronous, and the delay time depends on the size of the data and your network conditions.

You can change the wait for one second into a while loop to judge frame by frame, as follows.

while (DataResult.Count==0)
{
   yield return null;
}
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.