I was trying to check whether the player has any contact email set up. But after testing I realized that the "GetPlayerProfile" will require some time to get the info from (possibly) the server-side and process the data in the callback. So I google for a bit, and people suggesting using async method to wait for the result. So I came up with the following piece of code, but when Unity runs the following code, it seems to freeze (possibly dead loop). Any suggestions would be really appreciated!
public static bool PlayerHasContactEmail() { Func<Task<bool>> PlayerHasContactEmailDelegate = async () => { TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>(); var request = new GetPlayerProfileRequest() { PlayFabId = PlayFabSettings.staticPlayer.PlayFabId, ProfileConstraints = new PlayerProfileViewConstraints() { ShowContactEmailAddresses = true }, }; var callBackResult = false; PlayFabClientAPI.GetPlayerProfile( request, success => { tcs.SetResult(true); callBackResult = !success.PlayerProfile.ContactEmailAddresses.IsNullOrEmpty(); }, fail => { tcs.SetResult(true); callBackResult = false; Debug.LogError(fail.Error.ParseReadableString()); }); Debug.Log("Waiting for call back result"); await tcs.Task; Debug.Log($"Result Returned, player has ContactEmail: {callBackResult}"); return callBackResult; }; var result = PlayerHasContactEmailDelegate.Invoke(); return result.Result; }