diff --git a/Assets/Mirror/Core/NetworkReaderExtensions.cs b/Assets/Mirror/Core/NetworkReaderExtensions.cs index 94e56c639..d2196d4b2 100644 --- a/Assets/Mirror/Core/NetworkReaderExtensions.cs +++ b/Assets/Mirror/Core/NetworkReaderExtensions.cs @@ -280,9 +280,8 @@ public static T[] ReadArray(this NetworkReader reader) { int length = reader.ReadInt(); - // we write -1 for null - if (length < 0) - return null; + // 'null' is encoded as '-1' + if (length < 0) return null; // todo throw an exception for other negative values (we never write them, likely to be attacker) diff --git a/Assets/Mirror/Core/NetworkWriterExtensions.cs b/Assets/Mirror/Core/NetworkWriterExtensions.cs index f3021ce7c..6524e10ca 100644 --- a/Assets/Mirror/Core/NetworkWriterExtensions.cs +++ b/Assets/Mirror/Core/NetworkWriterExtensions.cs @@ -258,7 +258,7 @@ public static void WriteNetworkBehaviour(this NetworkWriter writer, NetworkBehav writer.WriteUInt(0); return; } - + // users might try to use unspawned / prefab NetworkBehaviours in // rpcs/cmds/syncvars/messages. they would be null on the other // end, and it might not be obvious why. let's make it obvious. @@ -352,11 +352,13 @@ public static void WriteHashSet(this NetworkWriter writer, HashSet hashSet public static void WriteArray(this NetworkWriter writer, T[] array) { + // 'null' is encoded as '-1' if (array is null) { writer.WriteInt(-1); return; } + writer.WriteInt(array.Length); for (int i = 0; i < array.Length; i++) writer.Write(array[i]);