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

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?

1 Like

You are changing scenes with NetworkSceneManager? If not you should.

Otherwise check that you aren’t violating any parenting rules:
https://docs-multiplayer.unity3d.com/netcode/current/advanced-topics/networkobject-parenting/#parenting-rules

Btw, what is that “destroy with scene” flag? I only know about “DontDestroy”.

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.

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.

That makes sense. Thank you