pomelo-unitychat-socket
pomelo-unitychat-socket copied to clipboard
Change scene error: get_loadedLevel can only be called from the main thread.
Press login and can't change scene:
get_loadedLevel can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
Here is what I did to fix the issue. Instead of calling it Application.loadscene in Entry (which is obsolete by the way, use SceneManager instead), do it in update instead. Just have a boolean that you can toggle. Example:
void Update(){
....
if (loadscene) {
//SceneManager.LoadScene("chat");
Application.LoadLevel(Application.loadedLevel + 1);
loadscene = false;
}
}
void Entry(){
....
pc.request("connector.entryHandler.enter", userMessage, (data)=>{
users = data;
loadscene = true;
});
....
}