Search Unity

LoadLevelAsync

Discussion in 'Multiplayer' started by TechnoObi, Nov 17, 2014.

  1. TechnoObi

    TechnoObi

    Joined:
    Nov 30, 2013
    Posts:
    82
    Hello!

    When I recive data from the server, I always get this error:
    "
    LoadLevelAsync 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.
    "

    But can I do against this?
     
  2. Glader

    Glader

    Joined:
    Aug 19, 2013
    Posts:
    456
    If you try to call various Unity3D engine functions, setters or getters on a thread other than the main game thread you usually get that exception thrown.

    Are you attempting to load a level in this fashion? You should not try to load a level from your network thread if you receive a request to do so from the server. Queue up a message and have the main thread handling loading a level.