Skip to content

Commit 2a77e53

Browse files
authored
refactor: extract GlobalObjectIdHash generation from NetworkObject.OnValidate() (#798)
1 parent f1c8612 commit 2a77e53

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

com.unity.multiplayer.mlapi/Runtime/Core/NetworkObject.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ public sealed class NetworkObject : MonoBehaviour
3030
// TAIL: DO NOT USE! TEST ONLY TEMP IMPL, WILL BE REMOVED
3131

3232
private void OnValidate()
33+
{
34+
GenerateGlobalObjectIdHash();
35+
}
36+
37+
internal void GenerateGlobalObjectIdHash()
3338
{
3439
// HEAD: DO NOT USE! TEST ONLY TEMP IMPL, WILL BE REMOVED
3540
if (TempGlobalObjectIdHashOverride != 0)
@@ -670,22 +675,22 @@ internal void SerializeSceneObject(NetworkWriter writer, ulong targetClientId)
670675
// Write placeholder size, NOT as a packed value, initially as zero (i.e. we do not know how much NetworkVariable data will be written yet)
671676
writer.WriteUInt32(0);
672677

673-
// Mark our current position before we potentially write any NetworkVariable data
678+
// Mark our current position before we potentially write any NetworkVariable data
674679
var positionBeforeNetworkVariableData = buffer.Position;
675680

676-
// Write network variable data
681+
// Write network variable data
677682
WriteNetworkVariableData(buffer, targetClientId);
678683

679684
// If our current buffer position is greater than our positionBeforeNetworkVariableData then we wrote NetworkVariable data
680685
// Part 1: This will include the total NetworkVariable data size, if there was NetworkVariable data written, to the stream
681686
// in order to be able to skip past this entry on the de-serialization side in the event this NetworkObject fails to be
682-
// constructed (See Part 2 below in the DeserializeSceneObject method)
687+
// constructed (See Part 2 below in the DeserializeSceneObject method)
683688
if (buffer.Position > positionBeforeNetworkVariableData)
684689
{
685-
// Store our current stream buffer position
690+
// Store our current stream buffer position
686691
var endOfNetworkVariableData = buffer.Position;
687692

688-
// Calculate the total NetworkVariable data size written
693+
// Calculate the total NetworkVariable data size written
689694
var networkVariableDataSize = endOfNetworkVariableData - positionBeforeNetworkVariableData;
690695

691696
// Move the stream position back to just before we wrote our size (we include the unpacked UInt32 data size placeholder)
@@ -742,7 +747,7 @@ internal static NetworkObject DeserializeSceneObject(NetworkBuffer objectStream,
742747

743748
if (networkVariableDataIsIncluded)
744749
{
745-
// (See Part 1 above in the NetworkObject.SerializeSceneObject method to better understand this)
750+
// (See Part 1 above in the NetworkObject.SerializeSceneObject method to better understand this)
746751
// Part 2: This makes sure that if one NetworkObject fails to construct (for whatever reason) then we can "skip past"
747752
// that specific NetworkObject but continue processing any remaining serialized NetworkObjects as opposed to just
748753
// throwing an exception and skipping the remaining (if any) NetworkObjects. This will prevent one misconfigured

0 commit comments

Comments
 (0)