Skip to content

Commit c5cbbc1

Browse files
committed
Reduced GetValue reflection calls in NetworkedVar init
1 parent 96d4a2a commit c5cbbc1

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,17 +953,14 @@ internal void NetworkedVarInit()
953953
Type fieldType = sortedFields[i].FieldType;
954954
if (fieldType.HasInterface(typeof(INetworkedVar)))
955955
{
956-
INetworkedVar instance = null;
957-
if (sortedFields[i].GetValue(this) == null)
956+
INetworkedVar instance = (INetworkedVar)sortedFields[i].GetValue(this);
957+
if (instance == null)
958958
{
959959
Type genericType = fieldType.MakeGenericType(fieldType.GetGenericArguments());
960960
instance = (INetworkedVar)Activator.CreateInstance(genericType, true);
961961
sortedFields[i].SetValue(this, instance);
962962
}
963-
else
964-
{
965-
instance = (INetworkedVar)sortedFields[i].GetValue(this);
966-
}
963+
967964
instance.SetNetworkedBehaviour(this);
968965
networkedVarFields.Add(instance);
969966
}

0 commit comments

Comments
 (0)