Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Change player position on scene change

Discussion in 'Connected Games' started by DespairBear, Jul 13, 2018.

  1. DespairBear


    Nov 1, 2013
    Hey all,

    Pretty simple question, so I have it setup so player's aren't destroyed when the scene changes and I'm trying to set each player's position to one of the spawn points in the new scene. I'm using the NetworkLobbyManager and was curious what method is the most effective way to get each player's transform position set? I keep running into issues with each method I've tried where the client's position gets changes for a few frames (only visible from the debug console, not to the human eye) but it quickly gets reset.

    I don't believe it's an issue with the character controller as the client is able to set its position just fine. Any tips or thoughts would be greatly appreciated

  2. DespairBear


    Nov 1, 2013
    a bit more info, so this is the code I'm using to set the player position:

    Code (CSharp):
    1. private void Start()
    2.     {
    3.         if (isLocalPlayer)
    4.         {
    5.             SceneManager.sceneLoaded += OnLevelFinishedLoading;
    6.         }
    7.         DontDestroyOnLoad(gameObject);
    8.     }
    10.     public void OnLevelFinishedLoading(Scene scene, LoadSceneMode mode)
    11.     {
    12.         if( == "Lobby")
    13.         {
    14.             return;
    15.         }
    16.         else
    17.         {
    18.             if(isLocalPlayer)
    19.             {
    20.                 Debug.Log("is local player!");
    21.                 transform.position = GameObject.FindGameObjectWithTag("Spawn").transform.position;
    22.             }
    23.         }
    24.     }
    The host's position is set just fine. However, the client, the position gets set and then is quickly reset back to the position it was in before the scene change.

    Would there be a better more centralized point to put this functionality? Perhaps overriding a method within the NetworkManager? New to multiplayer dev