HLAPI SyncVars property setter function

Hello,

I was reading through the HLAPI manual section on Unity’s website and got to this section about State Synchronization

Note that setting a SyncVar member variable inside a property setter function does not cause it to be dirtied. Trying to do this will cause a compile time warning. Because SyncVars use properties internally to mark themselves as dirty, setting them dirty inside property functions could lead to recursion problems.

Scenario: Lets say a server-side script wants to change the health of an object from 100 to 300. What is the proper way to do this? I am using a getter/setter and having this compiler warning.

UNetWeaver warning: SyncVar [curHealth] set from within property function [System.Void Health::set_CurrentHp(System.Int32)]. This will not set dirty flags.

public int CurrentHp{
	get { return curHealth; }
	set { curHealth = value;}
}
  1. Should I be using getters/setters for variables in the HLAPI or leaving all variables public? I’m not setting the dirty flag in the ‘setter’ portion because the mentioned recursion problems above.
  2. Are getter/setter methods even the correct thing to do with a game that is networked? ClientRpcs and Commands don’t seem right to use for this.

No. Dont use setters for SyncVars, they must be regular member variables.