Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Using NetworkManager player prefab with a parent and child

Discussion in 'Connected Games' started by _Kyle, Aug 10, 2018.

  1. _Kyle


    Jul 30, 2018
    I've got a parent and child object that I'm wanting as the player prefab. I need the parent to stay still and the child to move around the scene. I've got it to work when it's not attached to unitys network manager but when I set it as the prefab it doesn't work.

    Also, when I set just the child as it's own object in the prefab it works as well. The problem seems to be when I make it a child. Why might this be?
  2. Joe-Censored


    Mar 26, 2013
    I'm guessing you're running into issues of multiple NetworkIdentity components on a single prefab. Unet doesn't support NetworkIdentity components on child objects, only on the root object of the prefab. Unet doesn't support NetworkBehaviour components or built in network related components such as NetworkTransform on objects that do not have a NetworkIdentity component, so these also need to be on the root object of the prefab.

    You could use NetworkTransformChild on the parent object to reference the child object you want to move around and sync its position to clients, but NetworkTransformChild is pretty simplistic.

    My recommendation would be to make these two entirely separate prefabs and instantiate/spawn the second prefab on the server after the first prefab is spawned and just get a reference to this second object on the first object.