Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change scene error: get_loadedLevel can only be called from the main thread. #3

Open
gclsoft opened this issue Jul 12, 2014 · 1 comment

Comments

@gclsoft
Copy link

gclsoft commented Jul 12, 2014

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.
@gclsoft gclsoft changed the title Change scene error: 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. Change scene error: get_loadedLevel can only be called from the main thread. Jul 12, 2014
@tqtran7
Copy link

tqtran7 commented Feb 9, 2016

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;
  });
  ....
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants