RTS - One time information sharing

Hey, so I'm very new to pun and I started with a simple RTS like prototype.

So far I have player movement working with just a transform view. (Not typical for RTS, but whatever)

The map for the game is procedural. So I want the master client to generate a seed and share it with the others. This works right now. I do it with OnPhotonSerializeView. In there I do something like this:
if (PhotonNetwork.IsMasterClient)
{
    stream.SendNext(seed);
}
else
{
    if (seed == int.MinValue)
    {
        seed = (int)stream.ReceiveNext();
        GenerateMap(seed);
        DisplayMap();
    }
}
Which works. But I don't want to send the map seed all the time. Which I think happens. Right?

So how could I share the seed only when a new player connects?

And further on. If I add building placement. How do I share the info that I placed a building one time to all the players?
Overall: How do I share an information only one time. And maybe: How do I share a information to a new joined player?

Sorry if the question is hard to understand. But please point me in the right direction. Thanks everyone (:

Best Answers

  • Malace
    Malace
    edited April 2019 Answer ✓
    Well to be honest I'm after similar answers myself on the forum. What I have found so far.

    Each object on the map that will need updating will require its own pun mono class to control how it will sync on the network.

    As such I'm leaning to believe your map should not stream itself more than once.

    What you will likely need is a RPC call to tell the server to pass the seed to the joining client. It should then be able to recreate the map itself. Using the seed and the same method used by the host. (This is my understanding of seeding a procedural map.)

    If your map is a true random even with your seed value. Then you would have to stream its contents at the start to all players. Since lag and other things can bog down how quickly a player receives the map data. You also likely will have to have all players waiting until all have loaded the map and finished building it. Then start your game logic of starter base placement and let the players go.

    Buildings and units should have their own network view. With their own script to stream as they will be moving and need to be synced to all players. Spawning them though again will likely need to happen in a RPC to spawn your prefab. Then set its owner, controls, and other setup requirements. It will have a pun mono to stream its position. Using the photon spawn method. All players will have the unit spawned when this is called. When the server runs the RPC to spawn. The network view scripting takes over on the object itself.

    The part I seem to be stuck on myself is how to choose specific clients to send updates to on spawn. Without streaming them again until certain conditions are met. In the sense that I need to spawn units without the enemy player seeing them. At least until they are at the same location.
  • Lipsch
    Lipsch
    Answer ✓
    For anyone wondering. I now use the custom property synchronisation to share the map seed with the players. https://doc.photonengine.com/en-us/pun/current/gameplay/synchronization-and-state

Answers

  • Malace
    Malace
    edited April 2019
    Declare a one time bool.

    Check against that
    if its not true run the code above inside
    Flip it true after display the map is completed.
    private bool hasRun = false; 
    
     if(!hasRun){
    //place your seed master check and else in here.
    if (PhotonNetwork.IsMasterClient)
    {
        stream.SendNext(seed);
    }
    else
    {
        if (seed == int.MinValue)
        {
            seed = (int)stream.ReceiveNext();
            GenerateMap(seed);
            DisplayMap();
        }
    }
    //once that if else has finished set your bool to true;
    hasRun=true;
    }
    //once this has run once it won't run again unless you reset the bool directly. from this script..
  • Well this would work for the map problem since it has to run one time at the start of the game.

    But what if I place a building and want to share that information to everyone. Then I would have to make a variable that contains the latest changes I have to share and then unset the "hasRun" bool so it gets shared. Something like that..
    And the receiving clients would always need to "receiveNext" since you never know when someone places a building.

    I feel like that won't work out.
    What is the go to way to share something like that I just placed a building.
    And Information that I don't want to share all the time, but only after an action from the user?
  • Malace
    Malace
    edited April 2019 Answer ✓
    Well to be honest I'm after similar answers myself on the forum. What I have found so far.

    Each object on the map that will need updating will require its own pun mono class to control how it will sync on the network.

    As such I'm leaning to believe your map should not stream itself more than once.

    What you will likely need is a RPC call to tell the server to pass the seed to the joining client. It should then be able to recreate the map itself. Using the seed and the same method used by the host. (This is my understanding of seeding a procedural map.)

    If your map is a true random even with your seed value. Then you would have to stream its contents at the start to all players. Since lag and other things can bog down how quickly a player receives the map data. You also likely will have to have all players waiting until all have loaded the map and finished building it. Then start your game logic of starter base placement and let the players go.

    Buildings and units should have their own network view. With their own script to stream as they will be moving and need to be synced to all players. Spawning them though again will likely need to happen in a RPC to spawn your prefab. Then set its owner, controls, and other setup requirements. It will have a pun mono to stream its position. Using the photon spawn method. All players will have the unit spawned when this is called. When the server runs the RPC to spawn. The network view scripting takes over on the object itself.

    The part I seem to be stuck on myself is how to choose specific clients to send updates to on spawn. Without streaming them again until certain conditions are met. In the sense that I need to spawn units without the enemy player seeing them. At least until they are at the same location.
  • Alright, I'll take further investigation into RPC. I was surprised that I haven't seen a single RPC Method in the Tutorial I went through.
    Would you mind exchanging discord information? I think it would benefit both of us with direct discussions about pun and unity in general :smile:. If there are direct messages in this forum send me one if you're interested.
  • I sent my discord info over. Feel free to direct message me there. I don't always have discord launched. But I do get notifications for direct messages so I'll know to check in.
  • Lipsch
    Lipsch
    Answer ✓
    For anyone wondering. I now use the custom property synchronisation to share the map seed with the players. https://doc.photonengine.com/en-us/pun/current/gameplay/synchronization-and-state