Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Synchronizing a maze in the network

Discussion in 'Multiplayer' started by Kalissar, Jun 15, 2014.

  1. Kalissar

    Kalissar

    Joined:
    Jun 13, 2014
    Posts:
    1
    Hello everyone.

    I'm trying to make a small game where the point is to get out of a maze (as simple as "the first to escape wins")
    Now Randomness is the core of my idea, so it's very important that the maze is generated at runtime.
    The maze generation is not a problem, I've succeeded in generating a maze locally

    I'm using Photon.

    This is my current architecture :
    Empty game object GameController, who has a script component NetworkManager and a script component MazeGenerator.

    The MazeGenerator has (among other things) 2 methods, One to generate the theoric maze, and one to actually build the maze into the scene.

    Since all players must have the same maze, it's generated only once, by the master client in the OnCreatedRoom method.

    But then, how do I actually build the maze into the scene ? I tried several things
    Photon.instantiate... except there are so many walls that the master client runs out of photon view ID.
    Same for Photon.InstantiateSceneObject. The scene runs out of photon viewID.

    I thought about increasing the number of photon view ID, but then I have a lot of
    QueueIncomingReliableWarning because there are too many walls to observe at the same time (each wall need a Photon view to be photon instantiated)
    I think having so many SceneObjects is not a good idea.

    I feel like the maze should be generated, then built locally after the master client sends the generated maze to the other players. But what about late joining players ? How can I send the data of the generated maze through the network ? Should I use c# native networking functions ? Seems like a lot of trouble only for an initialization.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,021
    In best case, you build a maze generator that is initialized with some integer value and then generates the very same maze - no matter on which device. This way, you only need to sync the initial value to get the same maze for all players. You can save this value as Custom Room Property and generate the maze on late joining players.
    This would be the most effective way.

    In worst case, you need some way to serialize your built maze. Preferably as byte-array. This can also be saved ad Custom Room Property but it won't be as effective and there are limits to how much you can save (those are not well-defined and depend on network, clients, etc).

    So. Make your maze generator work with one initial integer and generate the GameObjects (non-network synced) on all devices.
     
  3. probbins

    probbins

    Joined:
    Oct 19, 2010
    Posts:
    216
    As suggested by tibiass, the best method would be to have a MazeGenerator on clients which use the same random seed value (int value).