Skip to content

Commit 25bfb07

Browse files
update
Migrating all NetworkTransform serialization into the NetworkTransformMessage. Removing legacy observers for the NetworkTransform.
1 parent e444a1b commit 25bfb07

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4493,38 +4493,6 @@ internal void UpdateParenting(NetworkObjectReference parent, bool worldPositionS
44934493
}
44944494
}
44954495

4496-
internal void SerializeMessage(FastBufferWriter writer, int targetVersion)
4497-
{
4498-
var networkObject = NetworkObject;
4499-
4500-
// Provides the source of the message (NetworkObject-->NetworkTransform : NetworkBehaviour)
4501-
BytePacker.WriteValueBitPacked(writer, NetworkObjectId);
4502-
BytePacker.WriteValueBitPacked(writer, (int)NetworkBehaviourId);
4503-
4504-
// Serialzie the state
4505-
writer.WriteNetworkSerializable(m_LocalAuthoritativeNetworkState);
4506-
4507-
// DA TODO: Update the CMB Service NetworkTransform protocol to
4508-
// handle this varying payload after the NetworkTransformState
4509-
// Serialzie any parenting directive
4510-
m_OutboundMessage.SerializeParent(writer);
4511-
4512-
if (m_CachedNetworkManager.DistributedAuthorityMode)
4513-
{
4514-
BytePacker.WriteValuePacked(writer, networkObject.Observers.Count - 1);
4515-
4516-
foreach (var targetId in networkObject.Observers)
4517-
{
4518-
if (OwnerClientId == targetId)
4519-
{
4520-
continue;
4521-
}
4522-
BytePacker.WriteValuePacked(writer, targetId);
4523-
}
4524-
}
4525-
4526-
}
4527-
45284496
/// <summary>
45294497
/// Invoked by the authoritative instance to sends a <see cref="NetworkTransformMessage"/> containing the <see cref="NetworkTransformState"/>
45304498
/// </summary>

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/NetworkTransformMessage.cs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ public void Serialize(FastBufferWriter writer, int targetVersion)
7373
else
7474
{
7575
var position = writer.Position;
76-
NetworkTransform.SerializeMessage(writer, targetVersion);
76+
// Provides the source of the message (NetworkObject-->NetworkTransform : NetworkBehaviour).
77+
BytePacker.WriteValueBitPacked(writer, NetworkTransform.NetworkObjectId);
78+
BytePacker.WriteValueBitPacked(writer, (int)NetworkTransform.NetworkBehaviourId);
79+
80+
// Serialize the current local state.
81+
writer.WriteNetworkSerializable(NetworkTransform.LocalAuthoritativeNetworkState);
82+
83+
// Write out any parenting directive associated with this update.
84+
SerializeParent(writer);
7785
BytesWritten = writer.Position - position;
7886
}
7987
}
@@ -163,22 +171,22 @@ public bool Deserialize(FastBufferReader reader, ref NetworkContext context, int
163171
{
164172
if (ownerAuthoritativeServerSide)
165173
{
166-
var targetCount = 1;
167-
168-
if (networkManager.DistributedAuthorityMode && networkManager.DAHost)
169-
{
170-
ByteUnpacker.ReadValueBitPacked(reader, out targetCount);
171-
}
174+
var targetCount = networkObject.Observers.Count;
172175

173176
var targetIds = stackalloc ulong[targetCount];
174177

175178
if (networkManager.DistributedAuthorityMode && networkManager.DAHost)
176179
{
177-
var targetId = (ulong)0;
178-
for (int i = 0; i < targetCount; i++)
180+
var count = 0;
181+
foreach (var targetId in networkObject.Observers)
179182
{
180-
ByteUnpacker.ReadValueBitPacked(reader, out targetId);
181-
targetIds[i] = targetId;
183+
targetIds[count] = targetId;
184+
count++;
185+
// Sanity check, this should never happen.
186+
if (count >= targetCount)
187+
{
188+
Debug.LogError($"[{nameof(NetworkTransformMessage)}] Exceeded total number of observers!");
189+
}
182190
}
183191
}
184192

0 commit comments

Comments
 (0)