Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Asset ID/Prefab syncronisation between two projects (Client/Server)

Discussion in 'Multiplayer' started by Freaking-Pingo, Jul 28, 2017.

  1. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    Hi all,

    I am trying to setup a prototype where client and server are developed in two different projects. I wish to use the HLAPI but I am experiencing problems. Because both server and client assets resides in two different projects their asset IDs do no tmatch. When the server instantiates a networked prefab the client throws the error:

    Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=befc9835522edc94bb82173088b9d7d5 netId=2

    I tried circumventing the issue using:
    Code (CSharp):
    1. ClientScene.RegisterPrefab(clientPrefab, NetworkHash128.Parse("befc9835522edc94bb82173088b9d7d5"));
    But that is only intended for procedurally generated prefabs who have no ID's assigned.

    I see two solutions:
    • I could modify the HLAPI implementation to be able to register a prefab under a different GUID. I am not sure whether this will produce some unforseen problems.
    • I could handle spawning using custom messaging instead, but I rather use the nifty HLAPI implemented prefab spawning features.
    How do you guys handle prefab instantiation in a two project setup?
     
  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    i've never tried this myself. either of your solutions would work, though neither sound particularly easy unfortunately. custom messaging sounds easy enough, but then you probably need to cook up your own net id system too to make it work for communications post-spawn

    i wonder if you could use asset bundles somehow?
     
  3. TwoTen

    TwoTen

    Joined:
    May 25, 2016
    Posts:
    1,168
    Custom mesaging is prolly the easiest. Alternativly, try to serialize the prefab meta files as YAML then modify the asset ID manually.
     
  4. Freaking-Pingo

    Freaking-Pingo

    Joined:
    Aug 1, 2012
    Posts:
    310
    @robochase I was actually thinking the same of using asset bundles, but I have never fully grasped the concept of using Asset Bundles and from the little experience I had it was very troublesome to use including a poor workflow.

    @Twote I think that would be possible. The only drawback I see, which is also present in my proposed solution, is that upon a reimport of the project wouldn't new ID's be generated and thus all prefabs have to be manually updated again to reflect the newly generated IDs?

    I went ahead and made a small tweak to the HLAPI and I ended up being able to use Create.Scene. So far it seems to be working, but I haven't gotten that far into testing it.
     
  5. acerpas10

    acerpas10

    Joined:
    Sep 22, 2018
    Posts:
    1
    My solution was to first create the prefab with a NetworkIdentity (and the assetID) in one project (server or client), then on this prefab i make "right click -> export package" and export this prefab to the other project that doesn't have the prefab, this way both projects will have the same prefab with the same assetID. Optionally, you can modify the prefab on one project and they will continue to have the same assetID.