Search Unity

Best practice for spawning a dynamically created level on multiplayer?

Discussion in 'Connected Games' started by Striph, Jun 13, 2018.

  1. Striph

    Striph

    Joined:
    Nov 17, 2012
    Posts:
    32
    I'm currently generating a procedural level on runtime, this works fine in the editor for single player testing but does not show up to any clients (not spawned as a network object is what I'm picking up from what I'm reading).

    My question is, whats the best practice for something like this? Should I instantiate it on the server, store it in a prefab somehow, then NetworkSpawn it to all of the clients? Or would it be a better idea to send the level seed to each client and let them spawn the level themselves?
     
  2. Ellernate

    Ellernate

    Joined:
    Aug 25, 2017
    Posts:
    81
    The first option won't work, prefabs need to be serialized in the build where they get their unique ids. The other option should work assuming there isn't any randomness or inaccuracy between simulations
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    4,650
    I'd send the level seed to the clients and have them generate the level using the same algorithm as the server. Otherwise you'd need to send the clients all the information they would need to construct the identical level, which could be complicated depending on the complexity of your levels.