Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Resolved NetworkObject does not despawn on scene change, when child of non scene object.

Discussion in 'Netcode for GameObjects' started by ervacoban, Oct 5, 2023.

  1. ervacoban

    ervacoban

    Joined:
    Oct 20, 2019
    Posts:
    6
    Hello. I am developing a multiplayer VR project using Netcode. The player object does not destroy itself on scene change. I have a network object spawner that spawns objects that I can hold in VR. This spawned object has the "destroy with scene" bool true. But while this spawned object is in my hand (child of the player), and I change the scene, this object does not get destroyed. Is this intentional? What could be a workaround for this? Or is this a bug?
     
    trombonaut likes this.
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,615
  3. ervacoban

    ervacoban

    Joined:
    Oct 20, 2019
    Posts:
    6
    Hello. Yes I am using the NetworkSceneManager to change scenes, and it works perfectly.

    Destroy with scene flag is used in code to spawn network objects. It can be set while using the NetworkObject.Spawn(destroyWithScene: false/true) function. It works perfectly as well, but the only problem is when a network object, whose destroy with scene flag is set to true, does not destroy it self on scene change, when its a child of a network object, whose destroy with scene flag is set to false.
     
  4. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    6,615
    That kind of sounds to me "by design".

    Imagine if you had another child in the to-be-destroyed object that has its flag set not to be destroyed. You wouldn't want that to go away but it would because the parent is set to be destroyed. Similar with your current parrent: it should not be destroyed, so none of its children should get destroyed either (it may be non-functional if that happened). I suppose you'd have to specifically code it to destroy the child in that case.
     
  5. ervacoban

    ervacoban

    Joined:
    Oct 20, 2019
    Posts:
    6
    That makes sense. Thank you