I have code like this:
NetworkVariable <...>_var = new()
[ClientRpc]
private void F(){}
void somwhereOnServer(){
_var.Value = somevalue;
F();
}
So, function F() executed on the client before then _var variable updated on the same client. On the client/host it’s updates as well. How can I fix the problem?
I could be wrong but I think the RPC is called immediately while the network variable update isn’t sent to the client until the next server tick.
1 Like
That’s absolutely crazy, every time you using rpc you can’t trust NetworkVariable. Also you cannot trust NetworkVariable is the same on different clients(practically proven). Another useless unitymade tool…
Network variables should be used for states and rpc’s for sending transient values. I’d recommend keeping them separate although maybe rpc’s will always arrive first, I’ve not tested it.
Network variables should match on all clients, or at least will eventually once the updates has been received. It’s worth keeping in mind updating multiple network variables on a particular object won’t necessarily update in the order they’re changed on the server/host.
It seems like its not in the dokumentation anymore OR it got changed. But it was once stated , in the documentation, that NetworkVariables can Sync on each Client differently. So if you change your Variable on Tick 1, Client 1 might geht the message on Tick 2 while Client 2 might get the message on Tick 3.
I remember reading it somewhere in the dokumentation.
A NetworkVariable is not a tool you use to replace RPCMessages, its more, like cerestorm mentioned, a tool to listen to a certain state that doesnt need global synchronisation
The docs recommended sending updated NetworkVariable via RPC as a parameter, which is dirty, and I already rebuilt code, and instead of independent scripts which use NetworkVariable after RPC call on client it became a dirty chain of transferring _val.
RPC vs NetworkVariable | Unity Multiplayer Networking.