Search Unity

Help Wanted Loading Assetbundle With Network Identity

Discussion in 'Testing & Automation' started by Togias, Mar 25, 2019.

  1. Togias

    Togias

    Joined:
    Jul 17, 2017
    Posts:
    5
    My application consists of a server and a client, I load some gameObjects as asset bundles at both server/client. The loaded gameObjects contain network identity and network transform but as I noticed when i load the objects and i move an object from the server it dose not follow its movement at the client.

    I am thinking that the network identity dose not much, as the objects that are loaded are 'not the same'. Any one has an idea on how to overcome this and make the loaded objects much and apply to the network transform. Thank you.
     
  2. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    156
    you need to at least manually register the prefabs.
    https://docs.unity3d.com/ScriptReference/Networking.ClientScene.RegisterPrefab.html

    this assures that when network spawning that same prefab on the server, the correct one will also be spawned on the client.
    there's one catch though. If you use the NetworkManager online scene and you allow late joining, the register call needs to be done in Awake. Otherwise it's too late because network traffic will be processed before OnStartClient is called
     
    Last edited: Apr 9, 2019
  3. Togias

    Togias

    Joined:
    Jul 17, 2017
    Posts:
    5
    Thank you for the reply, I manage to spawn the objects following the registration/spawn procedure. As I found out there is a Bug in the editor (my unity version 2018.2.5) where you are not able to spawn asset bundles in the network. It works only when the app is built.

    My problem continues even if I managed to spawn the objects because the asset bundles that I spawn are prefabs that inside their hierarchy mone objects with NetID exist. I was thinking that the best solution will be to load the asset bundles and then save them as prefabs.

    Do you have any experience at spawning network objects with nested objects with network Id?

    I also tried to register and spawn all the objects contained at the asset bundles but I had no good results, also the editor bug does not help with debugging...
     
  4. Alexees

    Alexees

    Joined:
    Nov 8, 2017
    Posts:
    156
    UNET does not allow nested NetworkIdentities. Whatever you want to do with children of a networked Gameobject, handle them from the root. If they're not meant to be actual children in a sense of networking them, don't child them.
     
  5. Togias

    Togias

    Joined:
    Jul 17, 2017
    Posts:
    5
    Thank you man, I concluded on spawning only the parent objects and then handle the transform of the rest with commands and clientRPC.
     
    Alexees likes this.