Skip to content

Commit 387f84b

Browse files
committed
Made SyncedVar hooks fire on host aswell as on clients.
1 parent 34c511c commit 387f84b

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,7 @@ internal void SyncVarUpdate()
593593
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo.GetValue(this), syncedVarFields[i].FieldValue);
594594
syncedVarFields[i].FieldValue = FieldTypeHelper.GetReferenceArrayValue(syncedVarFields[i].FieldInfo.GetValue(this), syncedVarFields[i].FieldValue);
595595
syncedVarFields[i].Dirty = false;
596+
invokeSyncvarMethodOnHost(syncedVarFields[i].HookMethod);
596597
}
597598
}
598599
List<uint> stillDirtyIds = InternalMessageHandler.Send("MLAPI_SYNC_VAR_UPDATE", "MLAPI_INTERNAL", writer, networkId);
@@ -628,6 +629,7 @@ internal void SyncVarUpdate()
628629
//Only targeted SyncedVars were changed. Thus we need to set them as non dirty here since it wont be done by the next loop.
629630
syncedVarFields[i].FieldValue = FieldTypeHelper.GetReferenceArrayValue(syncedVarFields[i].FieldInfo.GetValue(this), syncedVarFields[i].FieldValue);
630631
syncedVarFields[i].Dirty = false;
632+
invokeSyncvarMethodOnHost(syncedVarFields[i].HookMethod);
631633
}
632634
}
633635
}
@@ -658,6 +660,7 @@ internal void SyncVarUpdate()
658660
FieldTypeHelper.WriteFieldType(writer, syncedVarFields[i].FieldInfo.GetValue(this), syncedVarFields[i].FieldValue);
659661
syncedVarFields[i].FieldValue = FieldTypeHelper.GetReferenceArrayValue(syncedVarFields[i].FieldInfo.GetValue(this), syncedVarFields[i].FieldValue);
660662
syncedVarFields[i].Dirty = false;
663+
invokeSyncvarMethodOnHost(syncedVarFields[i].HookMethod);
661664
}
662665
}
663666
List<uint> stillDirtyIds = InternalMessageHandler.Send("MLAPI_SYNC_VAR_UPDATE", "MLAPI_INTERNAL", writer, ownerClientId, networkId, null, null); // Send to everyone except target.
@@ -670,6 +673,12 @@ internal void SyncVarUpdate()
670673
}
671674
}
672675

676+
void invokeSyncvarMethodOnHost(MethodInfo hookMethod)
677+
{
678+
if (hookMethod != null && isHost)
679+
hookMethod.Invoke(this, null);
680+
}
681+
673682
private bool SetDirtyness()
674683
{
675684
if (!isServer)

0 commit comments

Comments
 (0)