Sync value after player loaded scene

Hello everyone,

I'm trying to figure out how to synchronize a value when a new player loaded the scene. Let's say it's the health of a player. What I'm doing right now is when the new player loaded the scene, the master client will send RPCs that instantiate the players prefab on the new player and send some RPCs that set their health based on the health the players have on the master client.
Now a problem might occur when another players sends an RPC to everyone that decreases a players health. It might happen that this message is received by the new player before the master client messages arrive to instantiate the player prefab or set the health. When the master client still has the old value for the health and sends the old value, the new player won't have the most updated health value for that player.
I guess I could fix this by making everything first be send to the server and then to the other players. But I think this will have quite an impact on bandwidth and I'm not currently planning on using it for some sort of authorative master client idea.
I could also use NetworkSerializeView but I don't think this is a good idea for values that don't change often.

Any suggestions?

Comments

  • Hi,

    One possible approach is that clients send health not only on health change but also in reply to special 'getPlayerState' RPC request. Then you do not need master client for health. New player broadcasts 'getPlayerState' request and gets health RPC calls directly from other clients. Those updates are obviously synced with health changes.
  • Thanks for your response,

    So with that approach every client that has a player prefab will send an instantiate message to the player with some stats? So then the player who owns the player should be the only one that sends messages about what changed about himself? So then you have some sort of every-client authority? That way you spread the load a bit.
    If these are my options then I think I'll just disable late joining for now. I'm working on a coop game where i'll try to make players join as much as possible at the start of a game anyway, because it'll provide a better experience. I am actually already doing some things from the master client (like spawning and the progression of the game) now that I look at it, so maybe I'll go for that all the way at some point.

    Thanks for the help. :)
  • As I can see, the reason for possible health desynchronization is that health updated in 2 different ways at the same time: via master client when new created player notified and via rpc sent by player whose health changed. You should send all updates either by client's rpc (as I proposed) or via master client including for health changes. If your design is more like master-client then choose second way and update health changes calling rpc for master which will broadcast updates to all.