Search Unity

  1. 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

Asset Bundle's lose Network Identity Asset ID required for uNet spawning, Nested Prefabs

Discussion in 'Asset Bundles' started by Phedg1, Jan 17, 2019.

  1. Phedg1

    Phedg1

    Joined:
    Mar 3, 2015
    Posts:
    113
    The game I'm working on has the expectation that players will be able to download the source code, open it in Unity and create their own levels using premade prefabs. Those levels will then be saved as nested prefabs in asset bundles. The hope is that users will then be able to share those asset bundles with each other in order to play networked games together in the levels they've made and shared.

    However, when a level prefab is built into an asset bundle it seems the NetworkIdentity.assetId NetworkHash128 property isn't serialized and is lost, causing errors the error "Failed to spawn server object, did you forget to add it to the NetworkManager?" when the client joins the server. Saving the assetId as a string on the prefab and registering the prefab with ClientScene.RegisterPrefab(levelPrefab, NetworkHash128.Parse(assetIdString)) will get around this, allowing the levels to be loaded on the client. However, every networked prefab that's part of the level nested prefab seems to have no observers. This doesn't cause any errors because the level prefab was spawned successfully.

    The game is almost finished and is built around the uNet framework. I know it's been depreciated but Unity hasn't released an alternative which is just plain frustrating. Can anyone help? Thanks.
     
    Last edited: Jan 17, 2019
    Futurristic and Sam-DreamsMaker like this.
  2. Sam-DreamsMaker

    Sam-DreamsMaker

    Joined:
    May 2, 2015
    Posts:
    13
    Same for me
     
  3. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    271
    "download the source code, open it in Unity and create their own levels using premade prefabs"

    Where do the premade prefabs come from? Are you downloading a *.unitypackage with the source premade prefabs, or are you trying to use data loaded from an asset bundle?
     
  4. Futurristic

    Futurristic

    Joined:
    Jun 21, 2016
    Posts:
    35
    Hello Ryanc, I am facing similar problem when trying to download assets bundle file, assign it assetId at runtime and register it on Client side by ClientScene.RegisterSpawnHandler(assetId, SpawnObject, UnSpawnObject), script.
    I fallow the custom spawn handler given in link https://docs.unity3d.com/Manual/UNetCustomSpawning.html
    However, It spawn successfully on host but on client give me an error like
    OnObjectSpawn netId: 3 has invalid asset id in unity unet....
    OnObjectSpawn netId: 4 has invalid asset id in unity unet....so on...
    I am not able to file solution around it, when trying to Instantiate content by assets bundle....Help me please......

    Thanks....
     
unityunity