Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions com.unity.netcode.gameobjects/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Additional documentation and release notes are available at [Multiplayer Documen

### Fixed

- NestedNetworkVariables initialized with no value no longer throw an error. (#3891)

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public static List<T> GetChangedList()
}
}

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

public static void ReadHashSetDelta<T>(FastBufferReader reader, ref HashSet<T> value) where T : IEquatable<T>
public static void ReadHashSetDelta<T>(FastBufferReader reader, ref HashSet<T> value)
{
// 1 = full serialization, 0 = delta serialization
reader.ReadByteSafe(out byte full);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static void InitializeSerializer_List<T>()
/// Registeres a native hash set (this generic implementation works with all types)
/// </summary>
/// <typeparam name="T">The type of elements contained in the HashSet, must implement IEquatable</typeparam>
public static void InitializeSerializer_HashSet<T>() where T : IEquatable<T>
public static void InitializeSerializer_HashSet<T>()
{
NetworkVariableSerialization<HashSet<T>>.Serializer = new HashSetSerializer<T>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,12 @@ void INetworkVariableSerializer<List<T>>.ReadWithAllocator(FastBufferReader read

public void Duplicate(in List<T> value, ref List<T> duplicatedValue)
{
if (value == null)
{
duplicatedValue = null;
return;
}

if (duplicatedValue == null)
{
duplicatedValue = new List<T>();
Expand All @@ -351,7 +357,7 @@ public void Duplicate(in List<T> value, ref List<T> duplicatedValue)
}
}

internal class HashSetSerializer<T> : INetworkVariableSerializer<HashSet<T>> where T : IEquatable<T>
internal class HashSetSerializer<T> : INetworkVariableSerializer<HashSet<T>>
{
public void Write(FastBufferWriter writer, ref HashSet<T> value)
{
Expand Down Expand Up @@ -414,6 +420,12 @@ void INetworkVariableSerializer<HashSet<T>>.ReadWithAllocator(FastBufferReader r

public void Duplicate(in HashSet<T> value, ref HashSet<T> duplicatedValue)
{
if (value == null)
{
duplicatedValue = null;
return;
}

if (duplicatedValue == null)
{
duplicatedValue = new HashSet<T>();
Expand Down Expand Up @@ -496,6 +508,12 @@ void INetworkVariableSerializer<Dictionary<TKey, TVal>>.ReadWithAllocator(FastBu

public void Duplicate(in Dictionary<TKey, TVal> value, ref Dictionary<TKey, TVal> duplicatedValue)
{
if (value == null)
{
duplicatedValue = null;
return;
}

if (duplicatedValue == null)
{
duplicatedValue = new Dictionary<TKey, TVal>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,9 @@ public static void ResetState()

public NetworkVariable<HashSet<int>> ListCollectionServer = new NetworkVariable<HashSet<int>>(new HashSet<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<HashSet<int>> ListCollectionOwner = new NetworkVariable<HashSet<int>>(new HashSet<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<HashSet<int>> UninitializedHashSet;
public NetworkVariable<HashSet<HashSet<int>>> UninitializedNestedHashSet;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, HashSet<int>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, HashSet<int>>>();

Expand Down Expand Up @@ -1470,6 +1473,8 @@ public static void ResetState()

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);
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);
public NetworkVariable<Dictionary<int, Dictionary<int, SerializableObject>>> UninitializedNestedDictionary;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, Dictionary<int, SerializableObject>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, Dictionary<int, SerializableObject>>>>();

Expand Down Expand Up @@ -1777,6 +1782,8 @@ public static void ResetState()

public NetworkVariable<Dictionary<int, SerializableObject>> ListCollectionServer = new NetworkVariable<Dictionary<int, SerializableObject>>(new Dictionary<int, SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<Dictionary<int, SerializableObject>> ListCollectionOwner = new NetworkVariable<Dictionary<int, SerializableObject>>(new Dictionary<int, SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<Dictionary<int, SerializableObject>> UninitializedDictionary;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, SerializableObject>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, Dictionary<int, SerializableObject>>>();

Expand Down Expand Up @@ -2144,6 +2151,8 @@ public static void ResetState()

public NetworkVariable<List<List<SerializableObject>>> ListCollectionServer = new NetworkVariable<List<List<SerializableObject>>>(new List<List<SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<List<List<SerializableObject>>> ListCollectionOwner = new NetworkVariable<List<List<SerializableObject>>>(new List<List<SerializableObject>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<List<List<SerializableObject>>> UninitializedNestedList;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, List<List<SerializableObject>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<List<SerializableObject>>>>();

Expand Down Expand Up @@ -2443,6 +2452,8 @@ public static void ResetState()

public NetworkVariable<List<SerializableObject>> ListCollectionServer = new NetworkVariable<List<SerializableObject>>(new List<SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<List<SerializableObject>> ListCollectionOwner = new NetworkVariable<List<SerializableObject>>(new List<SerializableObject>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<List<SerializableObject>> UninitializedList;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, List<SerializableObject>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<SerializableObject>>>();

Expand Down Expand Up @@ -2708,6 +2719,8 @@ public static void ResetState()

public NetworkVariable<List<List<int>>> ListCollectionServer = new NetworkVariable<List<List<int>>>(new List<List<int>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<List<List<int>>> ListCollectionOwner = new NetworkVariable<List<List<int>>>(new List<List<int>>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<List<List<int>>> UninitializedList;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, List<List<int>>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<List<int>>>>();

Expand Down Expand Up @@ -3012,6 +3025,8 @@ public static void ResetState()

public NetworkVariable<List<int>> ListCollectionServer = new NetworkVariable<List<int>>(new List<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Server);
public NetworkVariable<List<int>> ListCollectionOwner = new NetworkVariable<List<int>>(new List<int>(), NetworkVariableReadPermission.Everyone, NetworkVariableWritePermission.Owner);
public NetworkVariable<List<int>> UninitializedList;

// This tracks what has changed per instance which is used to compare to all other instances
internal Dictionary<Targets, Dictionary<DeltaTypes, List<int>>> NetworkVariableChanges = new Dictionary<Targets, Dictionary<DeltaTypes, List<int>>>();

Expand Down
Loading