Skip to content

Commit e1cc0b6

Browse files
committed
Fixed an issue causing new objects to not have their SyncedVars inited
1 parent 6f1f035 commit e1cc0b6

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ private void OnDestroy()
206206
internal List<FieldType> syncedFieldTypes = new List<FieldType>();
207207
private List<object> syncedFieldValues = new List<object>();
208208
private List<MethodInfo> syncedVarHooks = new List<MethodInfo>();
209+
private bool syncVarInit = false;
209210
//A dirty field is a field that's not synced.
210211
private bool[] dirtyFields;
211212
internal void SyncVarInit()
212213
{
214+
syncVarInit = true;
213215
FieldInfo[] sortedFields = GetType().GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Instance).OrderBy(x => x.Name).ToArray();
214216
for (byte i = 0; i < sortedFields.Length; i++)
215217
{
@@ -453,6 +455,8 @@ internal void FlushToClient(int clientId)
453455
private float lastSyncTime = 0f;
454456
internal void SyncVarUpdate()
455457
{
458+
if (!syncVarInit)
459+
SyncVarInit();
456460
SetDirtyness();
457461
if(Time.time - lastSyncTime >= SyncVarSyncDelay)
458462
{

0 commit comments

Comments
 (0)