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

Question NetworkObject.Despawn() Issue with Late Joiners

Discussion in 'Netcode for GameObjects' started by afavar, Oct 9, 2023.

  1. afavar

    afavar

    Joined:
    Jul 17, 2013
    Posts:
    59
    I have an in scene placed network object and I am using the NetworkObject.Despawn() method on server to destroy it. This object also gets destroyed on connected clients but if a client joins the game after the despawn call, the object still appears in the scene. Am I missing sth?
     
  2. afavar

    afavar

    Joined:
    Jul 17, 2013
    Posts:
    59
    Just wanted to bump this thread as I still in need of help on this matter.
     
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    603
    I think that's to be expected as only the server/host does a sweep for in-scene network objects. You can destroy it manually in somewhere like OnClientConnectedCallback but I'm not sure it's possible on the object itself.
     
  4. danielbradley418

    danielbradley418

    Joined:
    Jun 14, 2020
    Posts:
    1
    Yeah this is definitely surprising behavior to me as well. I just recreated it to see what you're talking about. Even if you spawn in an object, then de-spawn it, and then bring in the late joiner, they will still see that GameObject. As if it records the spawning but not the de-spawning. Would you have to keep a manual table of all the NPCs / whether they're alive or not? That feels pretty inefficient.
     
  5. afavar

    afavar

    Joined:
    Jul 17, 2013
    Posts:
    59
    Actually, the object is not spawned when you look at the NetworkObject component but it isn't destroyed either. @RikuTheFuffs-U any idea how should we handle this scenario?