Search Unity

How can I Spawn an object with nested NetworkIdentity components in uNet?

Discussion in 'Connected Games' started by Phedg1, Jan 18, 2019.

  1. Phedg1

    Phedg1

    Joined:
    Mar 3, 2015
    Posts:
    106
    I've got a game that is almost finished. The game has multiple "rooms" which are Spawned at runtime to create a "level". These rooms all contain prefabs such as levers, doors and pressure plates that together make a puzzle that needs to be solved to open the next room. These levers and doors (etc) all have NetworkIdentity components so their states can be synched over the network. Previously I had a convoluted system for syncing additive scene loading over a network, something that uNet does not natively support, but with the addition of nested prefabs I figured it would make life simpler. The additive scene implementation simply had a number of bugs that could not be tracked down, hindering the play experience and making some clients unplayable.

    I've stripped all my additive scene loading code and have converted my room scenes into room nested prefabs. These prefabs are now spawned with NetworkServer.Spawn(). However, each room needs a NetworkIdentity in order to be spawned over the network. This means that none of the child prefabs, such as the levers and doors, are connected over the network.

    Instead, I removed the NetworkIdentity components from the rooms, instantiating them locally on the client and server. I then made the server spawn all the room objects objects with a NetworkIdentity component, and on the client I destroyed all the objects with a network identity component that was instantiated locally, waiting instead of the spawned objects to show up. I also registered every networked object from the rooms as spawnable prefabs on the client. However, these objects are spawned on the server with a consistent NetworkIdentity.assetId, of the base prefab, ie all levers have the same asset id. This isn't what I want because I want each lever or door in each level to have a unique asset id, so it can be spawned correctly configured on each client.

    If I could force the assetId of each room object on the server to be unique, I could then get the objects spawned correctly on the client. However, even then I'd have to rebuild all the references to the rest of the scene the object requires, and all the references to the object the scene requires. That property seems to be read only, so I cannot. I do not know a way around this. Can anyone help?

    I'm prepared to change network framework from uNet if anyone can confirm this functionality is implemented in another solution. I've found very little is known about the upcoming connected games implementation, does anyone know if this functionality will be supported in it?
     
    Last edited: Jan 18, 2019
  2. MrG

    MrG

    Joined:
    Oct 6, 2012
    Posts:
    296
    Additive scenes works in Mirror, but not in the asset store version (yet). You can take a release from GitHub though and give that a try.

    Migration doc is here.

    If you need help, come talk to us on Discord.
     
  3. Phedg1

    Phedg1

    Joined:
    Mar 3, 2015
    Posts:
    106
    Thanks. I was wondering if I could pm you and pick your brain about Mirror? It would be nice to be able to talk with someone familiar with the framework to see if it would be a suitable upgrade for me. I've joined the discord as well if you'd prefer to talk there.