Search Unity

Destroy network player and create a new one

Discussion in 'Multiplayer' started by Vallar, Oct 18, 2017.

  1. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Hey guys,

    I am trying to change scenes in UNET and when I do that I wanted to destroy the player spawned for the client in the first scene so I can spawn a new player in the second scene.

    Right now I am trying this but it isn't working. I get the below errors on client:
    • AddPlayer: playerControllerId is of -1 is negative.

    • A connection has already been set as ready. There can only be one.
    While on the server I get this error:
    • There is already a player at that playerControllerId for this connections. UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate().
    What am I doing wrong? How can I fix this?

    Thanks a lot in advance!
     
  2. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    Bump, I am still looking for solutions or any tips!
     
  3. martinmungard

    martinmungard

    Joined:
    Feb 7, 2018
    Posts:
    5
    Hey, I have the same problem...
    do you find a solution for that?
     
  4. Nigey

    Nigey

    Joined:
    Sep 29, 2013
    Posts:
    1,129
    I'm pretty new to UNET myself, but my solution is using NetworkLobbyManager. The LobbyGamePlayer always exists once past the lobby stage. That GameObject has a class that listens to SceneManager.activeSceneChange. When that event fires it checks that it's not the lobby, and then instantiates the player prefab, spawns it with authority, and that's it.

    I was going to use OnClientSceneChange, but that seems to fire before all the needed actions in the NetworkLobbyManager, not after.
     
  5. Vallar

    Vallar

    Joined:
    Oct 18, 2012
    Posts:
    177
    I didn't, no, sorry. Instead, I just put everything in one scene and started disabling/destroying stuff as I "change scenes".