Skip to content

Commit 9dbaf06

Browse files
fix: remove added parameter onsynchronize (#2471)
* fix Removing the added OnSynchronize parameter and using a protected property to avoid major version change. * test updating test
1 parent f2295c8 commit 9dbaf06

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

com.unity.netcode.gameobjects/Components/NetworkAnimator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ private void WriteSynchronizationData<T>(ref BufferSerializer<T> serializer) whe
765765
/// <summary>
766766
/// Used to synchronize newly joined clients
767767
/// </summary>
768-
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId)
768+
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
769769
{
770770
if (serializer.IsWriter)
771771
{

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1251,8 +1251,9 @@ private bool ShouldSynchronizeHalfFloat(ulong targetClientId)
12511251
/// <typeparam name="T"></typeparam>
12521252
/// <param name="serializer"></param>
12531253
/// <param name="targetClientId">the clientId being synchronized (both reading and writing)</param>
1254-
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId = 0)
1254+
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
12551255
{
1256+
var targetClientId = m_TargetIdBeingSynchronized;
12561257
var synchronizationState = new NetworkTransformState();
12571258

12581259
if (serializer.IsWriter)

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,22 @@ protected NetworkObject GetNetworkObject(ulong networkId)
897897
/// is in read mode or write mode.
898898
/// </typeparam>
899899
/// <param name="targetClientId">the relative client identifier being synchronized</param>
900-
protected virtual void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId = 0) where T : IReaderWriter
900+
protected virtual void OnSynchronize<T>(ref BufferSerializer<T> serializer) where T : IReaderWriter
901901
{
902902

903903
}
904904

905+
/// <summary>
906+
/// The relative client identifier targeted for the serialization of this <see cref="NetworkBehaviour"/> instance.
907+
/// </summary>
908+
/// <remarks>
909+
/// This value will be set prior to <see cref="OnSynchronize{T}(ref BufferSerializer{T})"/> being invoked.
910+
/// For writing (server-side), this is useful to know which client will receive the serialized data.
911+
/// For reading (client-side), this will be the <see cref="NetworkManager.LocalClientId"/>.
912+
/// When synchronization of this instance is complete, this value will be reset to 0
913+
/// </remarks>
914+
protected ulong m_TargetIdBeingSynchronized { get; private set; }
915+
905916
/// <summary>
906917
/// Internal method that determines if a NetworkBehaviour has additional synchronization data to
907918
/// be synchronized when first instantiated prior to its associated NetworkObject being spawned.
@@ -913,6 +924,7 @@ protected virtual void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulon
913924
/// <returns>true if it wrote synchronization data and false if it did not</returns>
914925
internal bool Synchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId = 0) where T : IReaderWriter
915926
{
927+
m_TargetIdBeingSynchronized = targetClientId;
916928
if (serializer.IsWriter)
917929
{
918930
// Get the writer to handle seeking and determining how many bytes were written
@@ -931,7 +943,7 @@ internal bool Synchronize<T>(ref BufferSerializer<T> serializer, ulong targetCli
931943
var threwException = false;
932944
try
933945
{
934-
OnSynchronize(ref serializer, targetClientId);
946+
OnSynchronize(ref serializer);
935947
}
936948
catch (Exception ex)
937949
{
@@ -947,6 +959,8 @@ internal bool Synchronize<T>(ref BufferSerializer<T> serializer, ulong targetCli
947959
}
948960
var finalPosition = writer.Position;
949961

962+
// Reset before exiting
963+
m_TargetIdBeingSynchronized = default;
950964
// If we wrote nothing then skip writing anything for this NetworkBehaviour
951965
if (finalPosition == positionBeforeSynchronize || threwException)
952966
{
@@ -1000,6 +1014,9 @@ internal bool Synchronize<T>(ref BufferSerializer<T> serializer, ulong targetCli
10001014
synchronizationError = true;
10011015
}
10021016

1017+
// Reset before exiting
1018+
m_TargetIdBeingSynchronized = default;
1019+
10031020
// Skip over the entry if deserialization fails
10041021
if (synchronizationError)
10051022
{

com.unity.netcode.gameobjects/Tests/Runtime/NetworkObject/NetworkObjectSynchronizationTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ public override void OnNetworkSpawn()
575575
base.OnNetworkSpawn();
576576
}
577577

578-
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId = 0)
578+
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
579579
{
580580
// Assign the failure type first
581581
m_MyCustomData.FailureType = m_FailureType.Value;
@@ -615,7 +615,7 @@ public override void OnNetworkSpawn()
615615
base.OnNetworkSpawn();
616616
}
617617

618-
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer, ulong targetClientId = 0)
618+
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
619619
{
620620
serializer.SerializeNetworkSerializable(ref CustomSerializationData);
621621
base.OnSynchronize(ref serializer);

0 commit comments

Comments
 (0)