Description
If you have the flag `EnsureNetworkVariableLengthSafety' on, this can cause synchronization to break.
I have some very large network behaviours and this caused it to not work as intended when a new client joins and have to sync the full network object, there were no error that could indicate to this matter.
Reproduce Steps
- Create a network variable that sends a message larger than a
ushort bytes
- Spawn that object with more than one client connected
Actual Outcome
Synchronization is broken.
Expected Outcome
Object is synced correctly between clients.
Environment
- OS: Windows 11 23H2
- Unity Version: 6000.0.32f1
- Netcode Version: 2.2.0
Additional Context
This is a mismatch between definitions.
In NetworkMessageManager.cs line 115
public int FragmentedMessageMaxSize = int.MaxValue;
Max message size is defined as MaxInt.
In NetworkBehaviour.cs line 1262
var varSize = (ushort)0;
varSize gets cast to ushort.
And if you have ensureLengthSafety on:
if (NetworkVariableFields[j].CanClientRead(clientId)) { if (ensureLengthSafety) { reader.ReadValueSafe(out varSize); if (varSize == 0) { Debug.LogError($"[{name}][NetworkObjectId: {NetworkObjectId}][NetworkBehaviourId: {NetworkBehaviourId}][{NetworkVariableFields[j].Name}] Expected non-zero size readable NetworkVariable! (Skipping)"); continue; } readStartPos = reader.Position; } }
If the size is larger than a ushort (as it can get up to Max Int), it will skip this and break.
Description
If you have the flag `EnsureNetworkVariableLengthSafety' on, this can cause synchronization to break.
I have some very large network behaviours and this caused it to not work as intended when a new client joins and have to sync the full network object, there were no error that could indicate to this matter.
Reproduce Steps
ushortbytesActual Outcome
Synchronization is broken.
Expected Outcome
Object is synced correctly between clients.
Environment
Additional Context
This is a mismatch between definitions.
In
NetworkMessageManager.csline 115public int FragmentedMessageMaxSize = int.MaxValue;Max message size is defined as MaxInt.
In
NetworkBehaviour.csline 1262var varSize = (ushort)0;varSizegets cast toushort.And if you have
ensureLengthSafetyon:if (NetworkVariableFields[j].CanClientRead(clientId)) { if (ensureLengthSafety) { reader.ReadValueSafe(out varSize); if (varSize == 0) { Debug.LogError($"[{name}][NetworkObjectId: {NetworkObjectId}][NetworkBehaviourId: {NetworkBehaviourId}][{NetworkVariableFields[j].Name}] Expected non-zero size readable NetworkVariable! (Skipping)"); continue; } readStartPos = reader.Position; } }If the size is larger than a
ushort(as it can get up toMax Int), it will skip this and break.