From 9227eacbbfc46144625be3dcfdaeed1d45e1a5cc Mon Sep 17 00:00:00 2001 From: vis2k Date: Sat, 21 Jul 2018 14:41:43 +0200 Subject: [PATCH] NetworkIdentity.UNetUpdate: component serialization size check moved to OnSerializeSafely so that it happens for both calling functions (UNetSerializeAllVars and UNetUpdate). Also simplifies UNetUpdate code and removes dependency on NetworkWriter.Position. --- .../Runtime/NetworkIdentity.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Unity-Technologies-networking/Runtime/NetworkIdentity.cs b/Unity-Technologies-networking/Runtime/NetworkIdentity.cs index cce1c0905..3fad30436 100644 --- a/Unity-Technologies-networking/Runtime/NetworkIdentity.cs +++ b/Unity-Technologies-networking/Runtime/NetworkIdentity.cs @@ -429,6 +429,13 @@ internal bool OnSerializeSafely(NetworkBehaviour comp, NetworkWriter writer, boo byte[] bytes = temp.ToArray(); if (LogFilter.logDebug) { Debug.Log("OnSerializeSafely written for object=" + comp.name + " component=" + comp.GetType() + " sceneId=" + m_SceneId + " length=" + bytes.Length); } + // original HLAPI had a warning in UNetUpdate() in case of large state updates. let's move it here, might + // be useful for debugging. + if (bytes.Length > NetworkServer.maxPacketSize) + { + if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + bytes.Length + " bytes for netId:" + netId + " from script:" + comp); } + } + // serialize length,data into the real writer, untouched by user code writer.WriteBytesAndSize(bytes); return result; @@ -684,10 +691,8 @@ internal void UNetUpdate() writer.Write(netId); bool wroteData = false; - int oldPos; for (int i = 0; i < m_NetworkBehaviours.Length; i++) { - oldPos = writer.Position; NetworkBehaviour comp = m_NetworkBehaviours[i]; if (comp.GetDirtyChannel() != channelId) { @@ -708,10 +713,6 @@ internal void UNetUpdate() wroteData = true; } - if (writer.Position - oldPos > NetworkServer.maxPacketSize) - { - if (LogFilter.logWarn) { Debug.LogWarning("Large state update of " + (writer.Position - oldPos) + " bytes for netId:" + netId + " from script:" + comp); } - } } if (!wroteData)