Search Unity

Keep player object after disconnect

Discussion in 'Multiplayer' started by Zelek, May 20, 2018.

  1. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    I'd like to keep the Player object around for a little while after a disconnect, so that players can't avoid dying by just disconnecting. Is there a clean supported way of doing this in UNET? You can override OnServerDisconnect() in your NetworkManager to avoid calling base.OnServerDisconnect(), but this generates a warning message. Can I safely ignore the warning? Is there some better option?
     
  2. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    I looked into doing this back in 2016 and it looked like yes you'd need to do it with a custom network manager, but I wasn't really happy with how I'd deal with certain corner cases. Between this issue and wanting custom characters, the solution I went with was having the Player gameobject spawn another gameobject that is the player's actual character. That gave me easy full control of when that separate character object is removed, and what custom prefab for this character is spawned.

    I use the Player gameobject for handling input and sending Commands to the server. Everything else I put on the character object. When a player connects, in the Player gameobject I check if their character object is currently active on the server, if it is then I just reference it, if not I spawn it. When the player gameobject is destroyed I tell the character object, which will start a timer to destroy itself in certain circumstances, or remove immediately in a safe zone, etc.

    This method works best in a slower paced game where you are fine with server authority over your character.
     
    Zelek likes this.
  3. stevesan

    stevesan

    Joined:
    Aug 14, 2011
    Posts:
    65
    I solved this issue by making the player object not actually the "real" player object. When a player connects, I create the "player object", but this doesn't do much. I then go through a fixed list of existing "pawns" and assign authority of the next free pawn to the new player.
     
    Zelek likes this.