Search Unity

  1. The 2022.1 beta is now available for testing. To find out what's new, have a look at our 2022.1 beta blog post.
    Dismiss Notice

Network prefabs with child network objects

Discussion in 'Netcode for GameObjects' started by cerestorm, Nov 24, 2021.

  1. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    118
    I want to have a hierarchical structure for some of the network objects I'm creating, with a parent and many children. Can this relationship be maintained automatically when they're spawned on a client, or do I have to wire them up manually?

    I should add the parent prefab is spawned from a script, it doesn't already exist in the scene.
     
    Last edited: Nov 24, 2021
  2. luke-unity

    luke-unity

    Unity Technologies

    Joined:
    Sep 30, 2020
    Posts:
    255
    We do not support spawning nested NetworkObjects at runtime. You can have nested NetworkObjects in your scene though. To spawn a hierarchical structure of NetworkObjects at runtime you'd have to make each element it's own prefab and register it in the NetworkManager, then instantiate and spawn all the elements and parent them to each other.
     
    cerestorm likes this.
  3. cerestorm

    cerestorm

    Joined:
    Apr 16, 2020
    Posts:
    118
    That was the conclusion I was coming to, thanks Luke.
     
  4. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    249
    But can it.. not do this and support nested? It goes against the design of Unity if you have to do your own nested concepts I think.
     
unityunity