Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

[MLAPI] Spawning NetworkObject Prefabs with NetworkObject as child

Discussion in 'Multiplayer' started by salvator23, May 1, 2021 at 2:04 PM.

  1. salvator23


    Sep 12, 2018

    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!