I’ve been trying to get my head around Unet and was hoping someone could explain what kind of cost (if any) SyncVars have in terms of network traffic.
I notice that NetworkTransform does not use SyncVars or Commands to communicate between server and client - is this because it cuts down on traffic or because the code is managing many scenarios?
I’m not really an authority in the field but I was just looking at NetworkIdentity’s UNetUpdate() method in unity networking’s source code and it seems that SyncVars are really just things that detect if a value has changed and then sends an actual Message (of the MsgType.UpdateVars type) to all valid connections
So basically, seems to me like SyncVars and Messages probably have the same cost
One comment/question: if you set a SynVar’s value to the same thing (i.e. set a [SyncVar] bool that is ‘false’ to ‘false’) will this trigger any hook functions on the SyncVar?
I didn’t expect that would be the case (i.e. to cut down on traffic) but in an earlier test it seems to trigger the hook function… Just wondering if anyone knows definitively. Next time I encounter that situation and discover the truth I will share here.
Whenever unity updates the syncVars using it’s update message it sends an additional int which is used as a bit field which says which of the vars are updated. So depends on your scenario.
If you will send a message per variable update and you only have one update, messages are better. If you have multiple variables, then syncvars send them all together and that one int probably is smaller than the message header of the multiple messages combined. You can create your own system which is not general/generic and sends multiple variables together but without the bitfield and be more optimized however but you can not use it as a general solution for everything.