Skip to content

Commit 33b273d

Browse files
ratijasLordfirespeed
authored andcommitted
ConfigSync: call base methods, use if-else chain for IsServer/IsClient
This change is intended to unify the code flow and to reduce diff size of the upcoming fixes. Normally, you'd want to call base class methods before your subclass logic to avoid working with a partially initialized state. Even though currently ConfigSyncBehaviour inherits directly from NetworkBehaviour, whose corresponding methods are empty, any of this might change in the future. So let's make the code more future-proof. For the reference, these are the values of variables at runtime: Host: Awake IsServer=False IsHost=False IsClient=False Spawn IsServer=True IsHost=True IsClient=True Despawn IsServer=True IsHost=True IsClient=True Client (Join): Awake IsServer=False IsHost=False IsClient=False Spawn IsServer=False IsHost=False IsClient=True Despawn IsServer=False IsHost=False IsClient=True
1 parent 3ddfcca commit 33b273d

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

CSync/CSync/Lib/ConfigSyncBehaviour.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ private void Awake()
5353

5454
public override void OnNetworkSpawn()
5555
{
56+
base.OnNetworkSpawn();
57+
5658
EnsureEntryContainer();
5759

5860
if (IsServer)
@@ -77,10 +79,8 @@ public override void OnNetworkSpawn()
7779
}
7880

7981
InitialSyncCompletedHandler?.Invoke(this, EventArgs.Empty);
80-
return;
8182
}
82-
83-
if (IsClient)
83+
else if (IsClient)
8484
{
8585
_syncEnabled.OnValueChanged += OnSyncEnabledChanged;
8686
_deltas.OnListChanged += OnClientDeltaListChanged;
@@ -96,6 +96,11 @@ public override void OnNetworkSpawn()
9696
}
9797
}
9898

99+
public override void OnNetworkDespawn()
100+
{
101+
base.OnNetworkDespawn();
102+
}
103+
99104
public override void OnDestroy()
100105
{
101106
DisableOverrides();

0 commit comments

Comments
 (0)