How to fix: InvalidParentException: Invalid parenting, NetworkObject moved under a non-NetworkObject parent

I’m working on multiplayer sirvival game and I need to parent an Item under hand in player prefab but I’m getting this error: InvalidParentException: Invalid parenting, NetworkObject moved under a non-NetworkObject parent and I don’t know what to do with it my whole system with items is based on that object under hand gameobject

image

I tried add Netowork object to hand but i got this error: Spawning NetworkObjects with nested NetworkObjects is only supported for scene objects. Child NetworkObjects will not be spawned over the network! becouse player-prefab have network object. technically i can add add tiem right under Player-prefab but in that case i will must write another script to make the item rotate with the camera, so i think that isn’t very effective.

Have anyone solution for this??

That‘s the rule: you can only spawn and then reparent a networkobject as child of another networkobject.

But most commonly the parenting isn‘t required. Consider that parenting GOs is merely a convenience feature. The alternative would be: Assign a parent transform to a component. Component sets its own position (and rotation, scale if needed) based on the parent transform in LateUpdate. Voila, you get practically the same behaviour but without parenting!

For networking it‘s widely recommended to avoid nested parenting as it only complicates matters.

1 Like