Search Unity

Resolved 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:
    660
    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

    Joined:
    Sep 30, 2020
    Posts:
    306
    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:
    660
    That was the conclusion I was coming to, thanks Luke.
     
  4. Vectrex

    Vectrex

    Joined:
    Oct 31, 2009
    Posts:
    267
    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.
     
    emredesu, randany, brainwipe and 2 others like this.
  5. Durium

    Durium

    Joined:
    Feb 1, 2020
    Posts:
    37
    If you can only have 1 object using network. How can a child object like a Player(network) sword swing?
     
  6. RikuTheFuffs-U

    RikuTheFuffs-U

    Unity Technologies

    Joined:
    Feb 20, 2020
    Posts:
    440
    @Durium Have you already had a look at the examples in the official ClientDriven sample?

    If not, you can download it here.

    Its examples show how to use the third person controller asset in a multiplayer environment for movement and picking objects up / moving them around
     
  7. Durium

    Durium

    Joined:
    Feb 1, 2020
    Posts:
    37
    Thanks for your reply! I had to attach a network transform on the child object :) !