Sync Property
For synchronizing not frequently updated GameObject States
Create Sync Property
Sync Properties are created in the Unity Editor Inspector by clicking the Add Sync Property button.
Maximum message size of a syncProperty is 4KB.

Name
Function
Name
Unique name of the Sync Property. Sync Property name must be unique in the same Sync Property Agent Component.
Type
Bool: Bool Property
Float: Float Property
Int: Int Property
String: String Property
Vector 3: Vector 3 Property
Vector 2: Vector 2 Property
Serializable: Serializable Property
TinyJSON: Any class and struct property
Conflict Resolution
Mine: takes the local change
Their: takes the remote change
Custom: use a custom method to resolve the conflict
Data
The current value of the Sync Property
Version
The current Version of the Sync Property
Events
Event
Description
OnValueChange
Invoked when the Sync Property is modified.
OnConflict
Invoked when conflict occurs and Conflict Resolution is set to Custom.
OnReady
invoked when the Sync Property finished fetching its value from the game server and is ready to be used.
Modify and Read Sync Property
Sync Properties can be modified by calling SWNetwork API in C# scripts
SyncPropertyAgent Class
Modify Sync Property
public void Modify(string name, bool value);
public void Modify(string name, int value);
public void Modify(string name, float value);
public void Modify(string name, string value);
public void Modify(string name, Vector2 value);
public void Modify(string name, Vector3 value);
public void Modify(string name, Vector4 value);
public void Modify(string name, Quaternion value);
public void Modify<T>(string name, T value);
public void ModifyTinyJson(string name, object value);
Get Sync Property
public SWSyncedProperty GetPropertyWithName(string name);
SWSyncedProperty Class
Read Sync property values
public int GetIntValue();
public bool GetBoolValue();
public float GetFloatValue();
public string GetStringValue();
public Vector2 GetVector2Value();
public Vector3 GetVector3Value();
public Vector4 GetVector4Value();
public Quaternion GetQuaternionValue();
public T GetValue<T>();
public T GetTinyJsonValue<T>();
Example
In this example, an Int Synced Property of name "hp" is modified.
public void GotHit(int damage)
{
SyncPropertyAgent syncPropertyAgent = gameObject.GetComponent<SyncPropertyAgent>();
// change hp to 100
syncPropertyAgent.Modify("hp", 100);
}
To get updates when a SyncProperty is modified, you can add a handler to the OnValueChange event of the SyncProperty.

public void OnHpChanged()
{
// read hp value
int currentHP = syncPropertyAgent.GetPropertyWithName("hp").GetIntValue();
}
Last updated
Was this helpful?