I have a player login sequence that uses coroutines, because it uses some calls to a server that perform sequentially.
It works fine when I log in via a login window in Unity. But now I want to modify it so that it logs in automatically using a token passed from the web page. I start this with a Javascript call. But if I call the login coroutine from the method that I call from Javascript, I get this message:
SystemException: Thread creation failed.
I thought that I could, instead of calling the coroutine directly, set a static bool with the Javascript call, and then when the Monobehavior instantiates, check for the static bool in an update, and if it’s set, call the coroutine. But I get the same error message as above using this method as well.
Does anyone have any ideas here? I can post code samples if needed.
Are you creating a Thread or a Coroutine? the exception suggests you are creating a Thread, which is something we don’t support at the moment.
I am calling a coroutine like this:
StartCoroutine(SignInFromWeb());
And it looks like this:
public IEnumerator SignInFromWeb()
{
yield return StartGetPlayer("current");
if (OnlineManager.Instance.PlayerReponseData.player.gamemaster)
{
GameManager.Clien t= false;
SceneManager.LoadScene("Moderator");
}
if (!OnlineManager.Instance.GetRequestFailure)
{
if(OnlineManager.Instance.PlayerID==null||OnlineManager.Instance.PlayerReponseData.status!="ok")
{
LoadingAlert.FinishLoading();
HTTPAlert.Present("LoginError",OnlineManager.Instance.Error,null,null,true);
}
else
{
yield return StartCoroutine(OnlineManager.Instance.StartGetGame());
yield return StartCoroutine(OnlineManager.Instance.StartGetGear());
Database.Instance.BuildAllData();
Database.Instance.BuildGearList();
PathManager.Instance.Initialize();
if(!Avatar.Instance.Embodied)
{
UIViewController.ActivateUIView(AvatarCreationView.Load());
UIViewController.ActivateUIView(AvatarStatsView.Load());
}
LoadingAlert.FinishLoading();
}
}
}
The confusing part for me is that I get the same error in the Javascript console when I try to call the coroutine from Update using the following code:
void Update()
{
if (_remoteLogin)
{
_webCounter++;
if (_webCounter > 3)
{
_remoteLogin = false;
StartCoroutine(SignInFromWeb());
enabled = false;
}
}
}