Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug: ClientScene.localPlayers not cleared after disconnecting

Discussion in 'Multiplayer' started by mischa2k, Jan 17, 2016.

  1. mischa2k

    mischa2k

    Joined:
    Sep 4, 2015
    Posts:
    4,347
    I attached a project with 11 lines of code where ClientScene.localPlayers acts like this:
    • list is empty at first
    • when selecting 'Start Host', the list gets one entry (the current player), everything fine so far
    • when selecting 'Stop', the list still has one entry but with invalid values like:
      • localPlayer: ID=0 NetworkIdentity NetID=null Player=null
    • after selecting 'Start Host' again, the list has a valid player entry again
    The behavior seems very inconsistent. I used "if ClientScene.localPlayers==0" to show a Character Selection mask as long as the Player didn't join the game world yet. This fails to work after disconnecting and then reconnecting again, because ClientScene.localPlayers will never be cleared.

    Reloading the Scene is a workaround, but that's somewhat hacky too, because often we set the NetworkManager to DontDestroyOnLoad, hence end up with two of them etc. Clearing the ClientScene.localPlayers list would make things much easier and probably confuse less people.

    Greetings
     

    Attached Files:

    wlwl2 likes this.
  2. dfjhde

    dfjhde

    Joined:
    May 23, 2015
    Posts:
    8
    i got the same problem, please help
     
    mischa2k likes this.
  3. Wriggler

    Wriggler

    Joined:
    Jun 7, 2013
    Posts:
    133
    I agree. This makes it very difficult to work with multiple local players, like in a split-screen game. When a player is removed using ClientScene.RemovePlayer() then it should also be removed from ClientScene.localPlayers IMO.

    Ben
     
  4. moco2k

    moco2k

    Joined:
    Apr 29, 2015
    Posts:
    294
    I also had the feeling that there might be some issues due to missing network manager cleanup across network game/scenes changes.

    Do you have already raised an official bug report for this? This will help to get some staff attention. Also, it would be helpful to have a link to the issue tracker id so that people can vote on the issue.
     
    Last edited: May 24, 2016
  5. Telgemannen

    Telgemannen

    Joined:
    Jun 10, 2015
    Posts:
    12
    I don't know how new this is, but playercontroller has a valid flag, so just filter by that. However, can someone explain to me why clientscene.addplayer adds 3 instances to the list, all of them invalid (no variables set, valid flag is false)?

    EDIT: Let me specify my question. I create a runnable and start it as a host. In the editor I join this host. all fine and dandy (btw, autocreateplayer is off). When I then try to create a player on the clientside with clientscene.addplayer(short), the clientscene localplayer list all of a sudden contains 3 instances, all invalid (it was empty before).
     
    Last edited: Aug 17, 2016
  6. analgorist

    analgorist

    Joined:
    Feb 5, 2017
    Posts:
    1
    To hijack this.
    I am on 5.6 and running into this.

    ClientScene.RemovePlayer() does indeed invalidate the entry in the list.

    BUT:

    NetworkServer.Destroy(); does not!

    I can easily extend the localPlayer list to only list valid entires but when I have destroyed the player object it did not get removed from the localPlayer list as a valid entry which means if I really want to do this right I have to manually update the localPlayer list when the Player is being destroyed. This seems very broken.