Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We are updating our Terms of Service for all Unity subscription plans, effective October 13, 2022, to create a more streamlined, user-friendly set of terms. Please review them here: unity.com/legal/terms-of-service.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice
  4. Join us on Thursday, September 29, for a day with Unity's SRP teams here on the forum or on Reddit, and discuss topics around URP, HDRP, and the Scriptable Render Pipeline in general.
    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:
    295
    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:
    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:
    295
    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.
     
    ChristopherSharp and Vaskrol like this.
unityunity