Skip to content

Commit 0afd693

Browse files
committed
Optimized SyncedVar dity checks
1 parent 67989a4 commit 0afd693

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,8 @@ internal void SyncVarUpdate()
454454
{
455455
if (!syncVarInit)
456456
SyncVarInit();
457-
if (SyncVarSyncDelay > 0 && NetworkingManager.singleton.NetworkTime - lastSyncTime >= SyncVarSyncDelay)
457+
if (SyncVarSyncDelay > 0 && NetworkingManager.singleton.NetworkTime - lastSyncTime >= SyncVarSyncDelay && SetDirtyness())
458458
{
459-
SetDirtyness();
460459
byte nonTargetDirtyCount = 0;
461460
byte totalDirtyCount = 0;
462461
byte dirtyTargets = 0;
@@ -568,17 +567,23 @@ internal void SyncVarUpdate()
568567
}
569568
}
570569

571-
private void SetDirtyness()
570+
private bool SetDirtyness()
572571
{
573572
if (!isServer)
574-
return;
573+
return false;
574+
575+
bool dirty = false;
575576
for (int i = 0; i < syncedVarFields.Count; i++)
576577
{
577578
if (!syncedVarFields[i].FieldInfo.GetValue(this).Equals(syncedVarFields[i].FieldValue))
579+
{
578580
syncedVarFields[i].Dirty = true; //This fields value is out of sync!
581+
dirty = true;
582+
}
579583
else
580584
syncedVarFields[i].Dirty = false; //Up to date;
581585
}
586+
return dirty;
582587
}
583588
#endregion
584589

0 commit comments

Comments
 (0)