Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Player objects lose isLocalPlayer after using ServerChangeScene()

Discussion in 'Multiplayer' started by benank, Sep 7, 2016.

  1. benank

    benank

    Joined:
    Mar 7, 2016
    Posts:
    4
    Basically the title. Everything works perfect when the players join and they all have their individual isLocalPlayer, but when I use ServerChangeScene() they lose it. They change the scene fine, but they don't have control over their player objects anymore. I'm using DontDestroyOnLoad() to keep the player objects persistent. Should I be keeping them persistent a different way?

    I've been struggling with this for a little bit now and it's the only thing stopping me from implementing the multiplayer side of my game.
     
  2. gintautass

    gintautass

    QA Minion Unity Technologies

    Joined:
    Oct 27, 2015
    Posts:
    46
    I have tried to reproduce this issue with no success using:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         DontDestroyOnLoad(gameObject);
    4.     }
    5.  
    6.     void Update ()
    7.     {
    8.         if(Input.GetKeyDown(KeyCode.Space))
    9.         {
    10.             Debug.Log("isLocalPlayer " + isLocalPlayer);
    11.         }
    12.  
    13.         if(Input.GetKeyDown(KeyCode.Tab))
    14.         {
    15.             Debug.Log("Changing scene "+isServer);
    16.             if(isServer)
    17.             {
    18.                 NetworkManager.singleton.ServerChangeScene("Scene2");
    19.             }
    20.         }
    21.     }
    Could you file a bug report with a project for this issue?
    If you do file a bug, please send me the case ID or write in the description to assign the case to Gintautas.

    Thanks!
     
  3. benank

    benank

    Joined:
    Mar 7, 2016
    Posts:
    4
    Thanks for your reply!

    I double checked and it turns out that I never used DontDestroyOnLoad(), though I was nearly certain I was using it. Thanks for making me double check my code and add it. Works great now!
     
    gintautass likes this.