Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    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.