Search Unity

NetworkStartPosition not registered until after player spawned.

Discussion in 'Multiplayer' started by glitchers, May 27, 2016.

  1. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    NetworkStartPosition not registered until after player spawned. This works fine in the editor but I am having this issue in builds.

    NetworkLobbyPlayer.OnLevelWasLoaded is used to send the ready message which changes the scene. but called before NetworkStartPosition can call Awake so my Players spawn at (0,0,0).

    I tried changing ScriptExecutionOrder but that didn't work. I also tried overriding the OnLevelWasLoaded and having a method call the SendSceneLoadedMessage() call from Start() (after Awake which should register the position) but that didn't work either.

    Has anyone had any similar experience? I am tempted to set the spawn position afterwards but I don't want to fix the symptom as the problem could materialise in a different way along further on in the project.

    Thank you
     
  2. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    I have managed to code around this issue if anyone finds this post.

    I have created a SceneDependencyManager which keeps a reference to all objects that must set themselves as ready (in my case, my re-implementation of NetworkSpawnTransform) and then will fire an event when all dependencies are ready.

    In LobbyPlayer I override OnLevelWasLoaded and add a snippet which checks if the scene is ready (all dependencies ready) and that sends the SceneLoadedMessage. If the scene isn't ready it registers itself with the SceneDependencyManager and fires off the event when all dependencies are ready.

    I imagine I will use this in other projects as well as I often have issues with running code on Scene load complete to the level that I need it to be. If anyone is interested in the code I will probably post it to our blog in the near future.
     
  3. Nodragem

    Nodragem

    Joined:
    May 20, 2017
    Posts:
    5
    hello! I got the same problem, 2 years after :)
    How do you check if the objects are ready on all clients?