Skip to content

Commit 314c913

Browse files
authored
Merge branch 'develop-2.0.0' into chore/remove-spawn-state-exceptions-network-object
2 parents cd12708 + e0e52f4 commit 314c913

File tree

5 files changed

+39
-4
lines changed

5 files changed

+39
-4
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
2222
- Removed un-needed exceptions on `NetworkObject.cs`. (#3867)
2323

2424
### Fixed
25+
2526
- Fixed `NetworkShow` behavior when it is called twice. (#3867)
27+
- NestedNetworkVariables initialized with no value no longer throw an error. (#3891)
2628

2729
### Security
2830

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Serialization/CollectionSerializationUtility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ public static List<T> GetChangedList()
281281
}
282282
}
283283

284-
public static void WriteHashSetDelta<T>(FastBufferWriter writer, ref HashSet<T> value, ref HashSet<T> previousValue) where T : IEquatable<T>
284+
public static void WriteHashSetDelta<T>(FastBufferWriter writer, ref HashSet<T> value, ref HashSet<T> previousValue)
285285
{
286286
// HashSets can be null, so we have to handle that case.
287287
// We do that by marking this as a full serialization and using the existing null handling logic
@@ -337,7 +337,7 @@ public static void WriteHashSetDelta<T>(FastBufferWriter writer, ref HashSet<T>
337337
}
338338
}
339339

340-
public static void ReadHashSetDelta<T>(FastBufferReader reader, ref HashSet<T> value) where T : IEquatable<T>
340+
public static void ReadHashSetDelta<T>(FastBufferReader reader, ref HashSet<T> value)
341341
{
342342
// 1 = full serialization, 0 = delta serialization
343343
reader.ReadByteSafe(out byte full);

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Serialization/TypedILPPInitializers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static void InitializeSerializer_List<T>()
103103
/// Registeres a native hash set (this generic implementation works with all types)
104104
/// </summary>
105105
/// <typeparam name="T">The type of elements contained in the HashSet, must implement IEquatable</typeparam>
106-
public static void InitializeSerializer_HashSet<T>() where T : IEquatable<T>
106+
public static void InitializeSerializer_HashSet<T>()
107107
{
108108
NetworkVariableSerialization<HashSet<T>>.Serializer = new HashSetSerializer<T>();
109109
}

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Serialization/TypedSerializerImplementations.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@ void INetworkVariableSerializer<List<T>>.ReadWithAllocator(FastBufferReader read
335335

336336
public void Duplicate(in List<T> value, ref List<T> duplicatedValue)
337337
{
338+
if (value == null)
339+
{
340+
duplicatedValue = null;
341+
return;
342+
}
343+
338344
if (duplicatedValue == null)
339345
{
340346
duplicatedValue = new List<T>();
@@ -351,7 +357,7 @@ public void Duplicate(in List<T> value, ref List<T> duplicatedValue)
351357
}
352358
}
353359

354-
internal class HashSetSerializer<T> : INetworkVariableSerializer<HashSet<T>> where T : IEquatable<T>
360+
internal class HashSetSerializer<T> : INetworkVariableSerializer<HashSet<T>>
355361
{
356362
public void Write(FastBufferWriter writer, ref HashSet<T> value)
357363
{
@@ -414,6 +420,12 @@ void INetworkVariableSerializer<HashSet<T>>.ReadWithAllocator(FastBufferReader r
414420

415421
public void Duplicate(in HashSet<T> value, ref HashSet<T> duplicatedValue)
416422
{
423+
if (value == null)
424+
{
425+
duplicatedValue = null;
426+
return;
427+
}
428+
417429
if (duplicatedValue == null)
418430
{
419431
duplicatedValue = new HashSet<T>();
@@ -496,6 +508,12 @@ void INetworkVariableSerializer<Dictionary<TKey, TVal>>.ReadWithAllocator(FastBu
496508

497509
public void Duplicate(in Dictionary<TKey, TVal> value, ref Dictionary<TKey, TVal> duplicatedValue)
498510
{
511+
if (value == null)
512+
{
513+
duplicatedValue = null;
514+
return;
515+
}
516+
499517
if (duplicatedValue == null)
500518
{
501519
duplicatedValue = new Dictionary<TKey, TVal>();

com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariable/NetworkVariableCollectionsTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ public static void ResetState()
12211221

12221222
public NetworkVariable<HashSet<int>> ListCollectionServer = new NetworkVariable<HashSet<int>>(new HashSet<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
12231223
public NetworkVariable<HashSet<int>> ListCollectionOwner = new NetworkVariable<HashSet<int>>(new HashSet<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
1224+
public NetworkVariable<HashSet<int>> UninitializedHashSet;
1225+
public NetworkVariable<HashSet<HashSet<int>>> UninitializedNestedHashSet;
1226+
12241227
// This tracks what has changed per instance which is used to compare to all other instances
12251228
internal Dictionary<Targets, Dictionary<DeltaTypes, HashSet<int>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, HashSet<int>>>();
12261229

@@ -1470,6 +1473,8 @@ public static void ResetState()
14701473

14711474
public NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>> ListCollectionServer = new NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>>(new Dictionary<int, Dictionary<int, SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
14721475
public NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>> ListCollectionOwner = new NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>>(new Dictionary<int, Dictionary<int, SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
1476+
public NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>> UninitializedNestedDictionary;
1477+
14731478
// This tracks what has changed per instance which is used to compare to all other instances
14741479
internal Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, Dictionary<int, SerializableObject>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, Dictionary<int, SerializableObject>>>>();
14751480

@@ -1777,6 +1782,8 @@ public static void ResetState()
17771782

17781783
public NetworkVariable<Dictionary<int, SerializableObject>> ListCollectionServer = new NetworkVariable<Dictionary<int, SerializableObject>>(new Dictionary<int, SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
17791784
public NetworkVariable<Dictionary<int, SerializableObject>> ListCollectionOwner = new NetworkVariable<Dictionary<int, SerializableObject>>(new Dictionary<int, SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
1785+
public NetworkVariable<Dictionary<int, SerializableObject>> UninitializedDictionary;
1786+
17801787
// This tracks what has changed per instance which is used to compare to all other instances
17811788
internal Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, SerializableObject>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, SerializableObject>>>();
17821789

@@ -2144,6 +2151,8 @@ public static void ResetState()
21442151

21452152
public NetworkVariable<List<List<SerializableObject>>> ListCollectionServer = new NetworkVariable<List<List<SerializableObject>>>(new List<List<SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
21462153
public NetworkVariable<List<List<SerializableObject>>> ListCollectionOwner = new NetworkVariable<List<List<SerializableObject>>>(new List<List<SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
2154+
public NetworkVariable<List<List<SerializableObject>>> UninitializedNestedList;
2155+
21472156
// This tracks what has changed per instance which is used to compare to all other instances
21482157
internal Dictionary<Targets, Dictionary<DeltaTypes, List<List<SerializableObject>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<List<SerializableObject>>>>();
21492158

@@ -2443,6 +2452,8 @@ public static void ResetState()
24432452

24442453
public NetworkVariable<List<SerializableObject>> ListCollectionServer = new NetworkVariable<List<SerializableObject>>(new List<SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
24452454
public NetworkVariable<List<SerializableObject>> ListCollectionOwner = new NetworkVariable<List<SerializableObject>>(new List<SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
2455+
public NetworkVariable<List<SerializableObject>> UninitializedList;
2456+
24462457
// This tracks what has changed per instance which is used to compare to all other instances
24472458
internal Dictionary<Targets, Dictionary<DeltaTypes, List<SerializableObject>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<SerializableObject>>>();
24482459

@@ -2708,6 +2719,8 @@ public static void ResetState()
27082719

27092720
public NetworkVariable<List<List<int>>> ListCollectionServer = new NetworkVariable<List<List<int>>>(new List<List<int>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
27102721
public NetworkVariable<List<List<int>>> ListCollectionOwner = new NetworkVariable<List<List<int>>>(new List<List<int>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
2722+
public NetworkVariable<List<List<int>>> UninitializedList;
2723+
27112724
// This tracks what has changed per instance which is used to compare to all other instances
27122725
internal Dictionary<Targets, Dictionary<DeltaTypes, List<List<int>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<List<int>>>>();
27132726

@@ -3012,6 +3025,8 @@ public static void ResetState()
30123025

30133026
public NetworkVariable<List<int>> ListCollectionServer = new NetworkVariable<List<int>>(new List<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
30143027
public NetworkVariable<List<int>> ListCollectionOwner = new NetworkVariable<List<int>>(new List<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
3028+
public NetworkVariable<List<int>> UninitializedList;
3029+
30153030
// This tracks what has changed per instance which is used to compare to all other instances
30163031
internal Dictionary<Targets, Dictionary<DeltaTypes, List<int>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<int>>>();
30173032

0 commit comments

Comments
 (0)