Search Unity

[MLAPI] Spawning NetworkObject Prefabs with NetworkObject as child

Discussion in 'Netcode for GameObjects' started by salvator23, May 1, 2021.

  1. salvator23

    salvator23

    Joined:
    Sep 12, 2018
    Posts:
    5
    Hey,

    I'm currently running in a bit of a problem with MLAPI:

    I have two GameObjects (banana and plate) which both have a NetworkObject component on them and both are registered in the NetworkManager under Network Prefabs.

    Now I create a third GameObject X (plate as parent and banana as a child), make a prefab out of that and register it in the Network Manager.

    If I now instantiate a new instance of the prefab X and spawn it, on the Client you can see the correct GameObject X with both the plate and the banana NetworkObjects being spawned. On the Host however the child-object (banana) is not spawned (it is possible to spawn it via inspector) and it is not possible to find the banana on the Host with GetNetworkObject(ulong netId).

    Spawning both the combined object X and the child (banana) would cause object X being correct on the Host, but on the Client there would be an additional banana.

    So what is the proper way to instantiate and spawn a GameObject like X?
    And why is the child-object not spawned on the Host but on the Client?

    I need both parts of object X to be and NetworkObject since I want it to be possible to take the banana from the plate and both being independent from eachother.

    Thanks in advance!
     
  2. LCGC_1

    LCGC_1

    Joined:
    Apr 2, 2019
    Posts:
    1
    Hi salvator23! Did you find a solution to your problem? We're running into the same issue
     
  3. luke-unity

    luke-unity

    Joined:
    Sep 30, 2020
    Posts:
    306
    Right now there is no simple way to spawn this sort of nested network prefab. What you could do is have the `plate` object instantiate and spawn a banana object in NetworkStart. That way you will end up with a separate plate and banana.