@@ -28,6 +28,28 @@ public class NetworkVariableSubclass<TSubclassName> : NetworkVariableMiddleclass
28
28
29
29
}
30
30
31
+ public class NetworkBehaviourWithNetVarArray : NetworkBehaviour
32
+ {
33
+ public NetworkVariable < int > Int0 = new NetworkVariable < int > ( ) ;
34
+ public NetworkVariable < int > Int1 = new NetworkVariable < int > ( ) ;
35
+ public NetworkVariable < int > Int2 = new NetworkVariable < int > ( ) ;
36
+ public NetworkVariable < int > Int3 = new NetworkVariable < int > ( ) ;
37
+ public NetworkVariable < int > Int4 = new NetworkVariable < int > ( ) ;
38
+ public NetworkVariable < int > [ ] AllInts = new NetworkVariable < int > [ 5 ] ;
39
+
40
+ public int InitializedFieldCount => NetworkVariableFields . Count ;
41
+
42
+
43
+ private void Awake ( )
44
+ {
45
+ AllInts [ 0 ] = Int0 ;
46
+ AllInts [ 1 ] = Int1 ;
47
+ AllInts [ 2 ] = Int2 ;
48
+ AllInts [ 3 ] = Int3 ;
49
+ AllInts [ 4 ] = Int4 ;
50
+ }
51
+ }
52
+
31
53
public struct TemplatedValueOnlyReferencedByNetworkVariableSubclass < T > : INetworkSerializeByMemcpy
32
54
where T : unmanaged
33
55
{
@@ -1435,6 +1457,40 @@ public void TestUnsupportedUnmanagedTypesWithUserSerializationDoNotThrowExceptio
1435
1457
UserNetworkVariableSerialization < Guid > . DuplicateValue = null ;
1436
1458
}
1437
1459
}
1460
+ [ Test ]
1461
+ public void WhenCreatingAnArrayOfNetVars_InitializingVariablesDoesNotThrowAnException ( )
1462
+ {
1463
+ var testObjPrefab = CreateNetworkObjectPrefab ( $ "NetVarArrayPrefab") ;
1464
+ var testComp = testObjPrefab . AddComponent < NetworkBehaviourWithNetVarArray > ( ) ;
1465
+ testComp . InitializeVariables ( ) ;
1466
+
1467
+ // Verify all variables were initialized
1468
+ Assert . AreEqual ( testComp . InitializedFieldCount , 5 ) ;
1469
+
1470
+ Assert . NotNull ( testComp . Int0 . GetBehaviour ( ) ) ;
1471
+ Assert . NotNull ( testComp . Int1 . GetBehaviour ( ) ) ;
1472
+ Assert . NotNull ( testComp . Int2 . GetBehaviour ( ) ) ;
1473
+ Assert . NotNull ( testComp . Int3 . GetBehaviour ( ) ) ;
1474
+ Assert . NotNull ( testComp . Int4 . GetBehaviour ( ) ) ;
1475
+
1476
+ Assert . NotNull ( testComp . Int0 . Name ) ;
1477
+ Assert . NotNull ( testComp . Int1 . Name ) ;
1478
+ Assert . NotNull ( testComp . Int2 . Name ) ;
1479
+ Assert . NotNull ( testComp . Int3 . Name ) ;
1480
+ Assert . NotNull ( testComp . Int4 . Name ) ;
1481
+
1482
+ Assert . AreNotEqual ( "" , testComp . Int0 . Name ) ;
1483
+ Assert . AreNotEqual ( "" , testComp . Int1 . Name ) ;
1484
+ Assert . AreNotEqual ( "" , testComp . Int2 . Name ) ;
1485
+ Assert . AreNotEqual ( "" , testComp . Int3 . Name ) ;
1486
+ Assert . AreNotEqual ( "" , testComp . Int4 . Name ) ;
1487
+
1488
+ Assert . AreSame ( testComp . AllInts [ 0 ] , testComp . Int0 ) ;
1489
+ Assert . AreSame ( testComp . AllInts [ 1 ] , testComp . Int1 ) ;
1490
+ Assert . AreSame ( testComp . AllInts [ 2 ] , testComp . Int2 ) ;
1491
+ Assert . AreSame ( testComp . AllInts [ 3 ] , testComp . Int3 ) ;
1492
+ Assert . AreSame ( testComp . AllInts [ 4 ] , testComp . Int4 ) ;
1493
+ }
1438
1494
1439
1495
private void TestValueType < T > ( T testValue , T changedValue ) where T : unmanaged
1440
1496
{
@@ -1562,7 +1618,6 @@ private void TestValueTypeNativeList<T>(NativeList<T> testValue, NativeList<T> c
1562
1618
clientVariable . Dispose ( ) ;
1563
1619
}
1564
1620
#endif
1565
-
1566
1621
[ Test ]
1567
1622
public void WhenSerializingAndDeserializingValueTypeNetworkVariables_ValuesAreSerializedCorrectly (
1568
1623
0 commit comments