I'm trying to upgrade my project from Unity 2019.4.20f1 to 2020.3.38f1 or 2021.3.11f1. I have editor-only code in the project to login to PlayFab and sync some items from Unity to PlayFab via the Admin API.
All of this works without issues in Unity 2019. However, the same code stops working in Unity 2020.3 and 2021.3 and can't figure out why.
I created an isolated test project with only the "login code", which again, works in Unity 2019. Opening the same project in 2020 or 2021 stops working with a "Request time out" error. I use the PlayFab Unity SDK that is linked on the github page.
Below you can find my test code. When you throw it in a Unity project where the PlayFab SDK is installed, it adds a "Test/Login" button to the main menu. Clicking this button will output "Auth token retrieved" in Unity 2019 and "Request time out" in Unity 2020/2021.
Any idea why it doesn't work in Unity 2020/2021 anymore?
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using PlayFab; using PlayFab.Internal; using PlayFab.SharedModels; using PlayFab.AuthenticationModels; using System.Threading; static class MyTestCode { [MenuItem("Test/Login")] static void DoLogin() { PluginManager.SetPlugin(new PlayFabWebRequest(), PluginContract.PlayFab_Transport); PlayFabWebRequest.SkipCertificateValidation(); Login(); Logout(); void Login() { PlayFabSettings.staticSettings.TitleId = "my title id"; PlayFabSettings.staticSettings.DeveloperSecretKey = "my secretkey"; var entityTokenRequest = new GetEntityTokenRequest(); var helper = new SyncCall<GetEntityTokenResponse>(); PlayFabAuthenticationAPI.GetEntityToken(entityTokenRequest, helper.Callback, helper.ErrorCallback); var result = helper.WaitForResponse(); if (result == null) { Debug.LogError(helper.error); } else { Debug.Log($"Auth token retrieved"); } } void Logout() { PlayFabSettings.staticSettings.TitleId = null; PlayFabSettings.staticSettings.DeveloperSecretKey = null; PlayFabSettings.staticPlayer.ForgetAllCredentials(); } } public class SyncCall<T> where T : PlayFabResultCommon { private const int k_DEFAULT_TIMEOUT = 1000 * 5; private PlayFabError m_Error; public PlayFabError error => m_Error; private T m_Response; public T WaitForResponse(int waitMs = -1) { var webRequest = PluginManager.GetPlugin<PlayFabWebRequest>(PluginContract.PlayFab_Transport); if (waitMs < 0) waitMs = k_DEFAULT_TIMEOUT; while (true) { //Manually pump the message queue inside PlayFabWebRequest //normally this is done during runtime from the PlayFabHTTP monobehaviour, but in the editor use-case //it has to be done manually webRequest.Update(); if (m_Response != null) return m_Response; if (m_Error != null) return null; //Wait that callback has been triggered, error has occured or timed out! Thread.Sleep(16); waitMs -= 16; if (waitMs >= 0) continue; Debug.LogWarning("Request timed out!"); return null; } } public void Callback(T response) { m_Response = response; } public void ErrorCallback(PlayFabError error) { m_Error = error; } } }