- Home /
Syncvar on procedural tiles
Hello, everyone, it's my first attempt on designing a multiplayer game.
I have a working lobby, the players are in sync as well.
The hex tile gameworld is defined (size, random seed ...) in the lobby. Every client then generates the same world. Here is the problem: If I change a variable on one of the tiles (for example the integer representing the climate), the change remains local. I have used Syncvar which works fine for anything else but the tiles.
I guess every player has a similar looking gameworld but because of the way I generate them, the tiles are all local? What is the best way to synchronize them?
GameObject hex_go = (GameObject)Instantiate (hexPrefab, new Vector3 (xPos, 0, y * zOffset), Quaternion.identity);
I know this doesn't directly solve the problem, but why not make the server decide on start up, a random "seed" to use? This seed is then synced (as a SyncVar or something) and recreated on the clients. It sounds way easier than syncing over a whole map imo
Sorry, I'm not as good at expressing myself in English as I'd wish to be. :-/
At the moment, the seed is assigned/generated by the host of the game or will be randomly chosen if it is a dedicated server. Afterwards, it is shared to all clients. There is a map generator game object in my scene which takes that seed for generating the map. So, if I understand you correctly, it already is the way you suggested and every player already starts with the identical map. The problem I have occurs during gameplay when players change the terrain. The changes they make are not synced although all corresponding variables are syncvar integers.
O$$anonymous$$G I'm an idiot I totally didn't see that... this is why I shouldn't just quickly reply to a question xD Your english is really good BTW, I didn't even realize you weren't a native speaker.
I do have one idea for your problem then. If I assume that your SyncVars are for the 3D coordinates and other such things, you may need to use a hook function to sync the changes. Something like this:
[SyncVar(hook="updateTerrain")]
float xValue;
void updateTerrain(float value) {
transform.position += new Vector3(value, 0, 0);
}
I haven't tested this or anything, but its an idea. Tell me if it works, and good luck!
Answer by Korahan · Oct 02, 2017 at 08:05 PM
I was finally able to solve the problem.
The map is generated on the server only now. When the map is completed, it is spawned by some very simple code:
foreach (GameObject tile in tiles) {
NetworkServer.Spawn (tile);
}
I also changed all player actions to commands. The server is now changing tiles if necessary and shares the information by the use of SyncVars.
After I figured it out, it seems quite obvious and easy to me and I feel capable to finish the development. But first I have to call my friends - it's time for them to suffer ... <^;..;^>
Your answer

Follow this Question
Related Questions
Networking: how to sync complex objects 0 Answers
Syncing times 0 Answers
Procedural terrain bug? 1 Answer
Procedural generation of dungeons with rooms made in the new tile map system? 0 Answers