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
  • Conflict Resolution Rules
  • Mine
  • Their
  • Custom

Was this helpful?

  1. SDK
  2. Game Play
  3. Sync Property

Conflict Resolution

Conflicts occur when competing changes are made to the same Sync Property. SocketWeaver game servers deliver Sync Property changes at very low latency. However, Sync Property conflicts are hard to eliminate. SWNetwork has an easy-to-use and flexible API to help you resolve the conflicts.

Conflict Resolution Rules

Mine

Use the local player's change as the merge result.

Their

Use remote change as the merge result.

Custom

On Conflict Event

Invoked when conflict occurs and Conflict Resolution is set to Custom.

In this example, a conflict was detected when the local player tried to modify the "hp" sync property.

To resolve the conflict

  1. Obtain oldLocalHP, newLocalHP, and remoteHP from the SWSyncConflict object

  2. Check if the player HP is already 0. If it is true, we should not apply damage to the dead player. We can just resolve the conflict by calling Resolve(Object resolvedValue) on the SWSyncProperty Object.

  3. If player HP is not 0, we should apply damage to the remoteHP instead of oldLocalHP.

void OnDamageConflict(SWSyncConflict conflict, SWSyncedProperty property)
{
    // 1
    int newLocalHP = (int)conflict.newLocalValue;
    int oldLocalHP = (int)conflict.oldLocalValue;
    int remoteHP = (int)conflict.remoteValue;
    
    // 2
    // check if player is already killed
    if (remoteHP == 0) {
        property.Resolve(0);
        return;
    }
    
    // 3
    // should use remoteHP instead of oldLocalHP to apply damage
    int damage = oldLocalHP - newLocalHP;
    int resolvedHP = remoteHP - damage;
    if (resolvedHP < 0) {
        resolvedHP = 0;
    }
    property.Resolve(resolvedHP);
}

PreviousRestore Sync PropertiesNextSceneSpawner

Last updated 5 years ago

Was this helpful?