LogoLogo
  • SWNetwork SDK Overview
  • Installation
    • Custom Unity Package
  • Tutorials
    • Third-Person Shooter
      • Starter Project Introduction
      • Install SWNetwork
      • Setting up the NetworkClient
      • Sync Player Transform
      • Setting up the Scene Spawner
      • Test and Play
      • Remote Events
      • SyncProperties
      • Player Respawn
      • Updating Room States
      • Winning the Game
    • Basic Lobby
      • Lobby-start
      • Installing SWNetwork SDK and configuring NetworkClient
      • Registering Player
      • Room CRUD
      • Managing Teams
      • Chat
  • SDK
    • Network Client
      • Check-in
      • Game Servers
      • Network Status Event (beta)
      • Classes
        • NetworkClient Class
      • Methods
        • CheckIn() Method
        • ConnectToRoom(Action<bool>) Method
        • DisconnectFromRoom () Method
        • FindSpawner(ushort) Method
    • Game Play
      • Network ID
      • Realtime Agent
      • Remote Event
      • Sync Property
        • Restore Sync Properties
        • Conflict Resolution
      • SceneSpawner
      • RoomPropertyAgent
      • RoomRemoteEventAgent
    • Lobby
      • Register Player
      • Message Player
      • Create Room
      • Change Room Settings
      • Get Rooms
      • Filter Rooms
      • Join Room
      • Message Room
      • Get Players in Room
      • Get Room Custom Data
      • Change Room Custom Data
      • Kick Players
      • Start Room
      • Leave Room
      • Lobby Room Events
        • OnLobbyConnectedEvent
        • OnPlayerMessageEvent
        • OnRoomCustomDataChangeEvent
        • OnNewPlayerJoinRoomEvent
        • OnPlayerLeaveRoomEvent
        • OnNewRoomOwnerEvent
        • OnRoomStartingEvent
        • OnRoomReadyEvent
        • OnFailedToStartRoomEvent
        • OnKickedEvent
        • OnRoomMessageEvent
      • Classes
        • SWLobby Class
        • SWPlayer Class
        • SWRoom Class
        • SWRegisterReply Class
        • SWGetRoomReply Class
        • SWJoinRoomReply Class
        • SWGetRoomCustomDataReply Class
        • SWGetPlayersReply Class
        • SWLobbyIndexData Class
        • SWLobbyFilterData Class
        • SWGetRoomFilterReply Class
        • SWLobbyError Class
        • SWMessagePlayerEventData Class
        • SWMessageRoomEventData Class
        • SWRoomCustomDataChangeEventData Class
        • SWJoinRoomEventData Class
        • SWLeaveRoomEventData Class
        • SWRoomChangeOwnerEventData Class
        • SWStartRoomEventData Class
        • SWRoomReadyEventData Class
        • SWFailedToStartRoomEventData Class
      • Methods
        • Register(Action<bool, SWRegisterReply, SWLobbyError>) Method
        • MessagePlayer(string, string, Action<bool, SWLobbyError>) Method
        • CreateRoom(bool, int, Action<bool, string, SWLobbyError>) Method
        • ChangeRoomSettings(int, int, Action<bool, SWLobbyError>) Method
        • GetRooms(int, int, Action<bool, SWGetRoomReply, SWLobbyError>) Method
        • FilterRoom(SWLobbyFilterData, byte, Action<bool, SWGetRoomFilterReply, SWLobbyError>) Method
        • JoinRoom(string, Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • JoinRoomRandomly(Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • JoinOrCreateRoom(bool, int, int, Action<bool, SWJoinRoomReply, SWLobbyError>) Method
        • MessageRoom(string, Action<bool, SWLobbyError>) Method
        • GetRoomCustomData(Action<bool, SWGetRoomCustomDataReply, SWLobbyError>) Method
        • GetPlayersInRoom(Action<bool, SWGetPlayersReply, SWLobbyError>) Method
        • ChangeRoomCustomData(string, Action<bool, SWLobbyError>) Method
        • StartRoom(Action<bool, SWLobbyError>) Method
        • LeaveRoom(Action<bool, SWLobbyError>) Method
  • Open Source Software Used
    • Credits
Powered by GitBook
On this page
  • Create Sync Property
  • Events
  • Modify and Read Sync Property
  • Example

Was this helpful?

  1. SDK
  2. Game Play

Sync Property

For synchronizing not frequently updated GameObject States

PreviousRemote EventNextRestore Sync Properties

Last updated 5 years ago

Was this helpful?

Create Sync Property

Sync Properties are created in the Unity Editor Inspector by clicking the Add Sync Property button.

You can have up to 250 Sync Properties in one Sync Property Agent.

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();
    }