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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NetworkServer.Destroy() issue when player disconnects

Discussion in 'Multiplayer' started by tinman, Sep 18, 2015.

  1. tinman

    tinman

    Joined:
    Jan 8, 2011
    Posts:
    229
    When one of my players is killed, his character, which is spawned on the network when he connects, get's destroyed by calling NetworkServer.Destroy() on the server. This destroys his object on the server and clients as expected. However, when that player disconnects, the server has an issue and creates an exception:

    "MissingReferenceException: The object of type 'NetworkIdentity' has been destroyed but you are still trying to access it.
    "

    As if the server still thinks that that player object should still be around. How would it be possible to resolve this?

    Thank you

    @seanr (noticed you were answering questions, hope it's OK I tagged :) )
     
    Last edited: Sep 18, 2015
  2. Firoball

    Firoball

    Joined:
    Aug 6, 2015
    Posts:
    60
    As the player gameobject is the access point for any command to be sent to the server, it's not a good idea to kill it.
    The player should always exist as long as the client is connected.

    But you can set the gameobject to invisible or maybe try out some things with NetworkServer.ReplacePlayerForConnection
     
  3. tinman

    tinman

    Joined:
    Jan 8, 2011
    Posts:
    229
    Wouldn't it be more the networkIdentity that would be responsible for any messages, which can be on player objects -or- non player objects which send messages. I would think it would make sense to be able to destroy and create objects across the network when needed.
     
  4. Firoball

    Firoball

    Joined:
    Aug 6, 2015
    Posts:
    60
    Quoting the manual...

    Destroy the player and you destroy the "gate" ;)