Skip to content

Commit 639fbf8

Browse files
update - pvp
Adding updates to resolve PVP issues for NetworkTransform.
1 parent 91eca5f commit 639fbf8

File tree

2 files changed

+37
-27
lines changed

2 files changed

+37
-27
lines changed

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ internal set
420420
/// UseUnreliableDeltas is enabled. When set, the entire transform will
421421
/// be or has been synchronized.
422422
/// </summary>
423+
/// <returns>true or false as to whether this state update was an unreliable frame synchronization.</returns>
423424
public bool IsUnreliableFrameSync()
424425
{
425426
return UnreliableFrameSync;
@@ -432,6 +433,7 @@ public bool IsUnreliableFrameSync()
432433
/// <remarks>
433434
/// Unreliable delivery will only be used if <see cref="UseUnreliableDeltas"/> is set.
434435
/// </remarks>
436+
/// <returns>true or false as to whether this state update was sent with reliable delivery.</returns>
435437
public bool IsReliableStateUpdate()
436438
{
437439
return ReliableSequenced;
@@ -615,9 +617,7 @@ public int GetNetworkTick()
615617

616618
internal HalfVector3 HalfEulerRotation;
617619

618-
/// <summary>
619-
/// Serializes this <see cref="NetworkTransformState"/>
620-
/// </summary>
620+
/// <inheritdoc />
621621
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
622622
{
623623
// Used to calculate the LastSerializedSize value
@@ -1038,11 +1038,25 @@ public enum InterpolationTypes
10381038
[Range(0.01f, 1.0f)]
10391039
public float ScaleMaxInterpolationTime = 0.1f;
10401040

1041+
/// <summary>
1042+
/// Determines if the server or client owner pushes transform states.
1043+
/// </summary>
10411044
public enum AuthorityModes
10421045
{
1046+
/// <summary>
1047+
/// Server pushes transform state updates
1048+
/// </summary>
10431049
Server,
1050+
/// <summary>
1051+
/// Client owner pushes transform state updates.
1052+
/// </summary>
10441053
Owner,
10451054
}
1055+
1056+
/// <summary>
1057+
/// Determines whether this <see cref="NetworkTransform"/> instance will have state updates pushed by the server or the client owner.
1058+
/// <see cref="AuthorityModes"/>
1059+
/// </summary>
10461060
#if MULTIPLAYER_SERVICES_SDK_INSTALLED
10471061
[Tooltip("Selects who has authority (sends state updates) over the transform. When the network topology is set to distributed authority, this always defaults to owner authority. If server (the default), then only server-side adjustments to the " +
10481062
"transform will be synchronized with clients. If owner (or client), then only the owner-side adjustments to the transform will be synchronized with both the server and other clients.")]
@@ -1052,7 +1066,6 @@ public enum AuthorityModes
10521066
#endif
10531067
public AuthorityModes AuthorityMode;
10541068

1055-
10561069
/// <summary>
10571070
/// When enabled, any parented <see cref="NetworkObject"/>s (children) of this <see cref="NetworkObject"/> will be forced to synchronize their transform when this <see cref="NetworkObject"/> instance sends a state update.<br />
10581071
/// This can help to reduce out of sync updates that can lead to slight jitter between a parent and its child/children.
@@ -1312,7 +1325,14 @@ internal bool SynchronizeScale
13121325
/// </remarks>
13131326
public bool SwitchTransformSpaceWhenParented = false;
13141327

1328+
/// <summary>
1329+
/// Returns true if position is currently in local space and false if it is in world space.
1330+
/// </summary>
13151331
protected bool PositionInLocalSpace => (!SwitchTransformSpaceWhenParented && InLocalSpace) || (m_PositionInterpolator != null && m_PositionInterpolator.InLocalSpace && SwitchTransformSpaceWhenParented);
1332+
1333+
/// <summary>
1334+
/// Returns true if rotation is currently in local space and false if it is in world space.
1335+
/// </summary>
13161336
protected bool RotationInLocalSpace => (!SwitchTransformSpaceWhenParented && InLocalSpace) || (m_RotationInterpolator != null && m_RotationInterpolator.InLocalSpace && SwitchTransformSpaceWhenParented);
13171337

13181338
/// <summary>
@@ -1575,16 +1595,12 @@ private bool ShouldSynchronizeHalfFloat(ulong targetClientId)
15751595

15761596
#region ONSYNCHRONIZE
15771597

1578-
/// <summary>
1579-
/// This is invoked when a new client joins (server and client sides)
1580-
/// Server Side: Serializes as if we were teleporting (everything is sent via NetworkTransformState)
1581-
/// Client Side: Adds the interpolated state which applies the NetworkTransformState as well
1582-
/// </summary>
1598+
/// <inheritdoc />
15831599
/// <remarks>
1584-
/// If a derived class overrides this, then make sure to invoke this base method!
1600+
/// This is invoked when a new client joins (server and client sides).
1601+
/// Server Side: Serializes as if we were teleporting (everything is sent via NetworkTransformState).
1602+
/// Client Side: Adds the interpolated state which applies the NetworkTransformState as well.
15851603
/// </remarks>
1586-
/// <typeparam name="T">The serializer type for buffer operations</typeparam>
1587-
/// <param name="serializer">The buffer serializer used for network state synchronization</param>
15881604
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
15891605
{
15901606
var targetClientId = m_TargetIdBeingSynchronized;
@@ -2345,6 +2361,9 @@ internal void UpdatePositionInterpolator(Vector3 position, double time, bool res
23452361

23462362
internal bool LogMotion;
23472363

2364+
/// <summary>
2365+
/// Virtual method invoked on the non-authority side after a new state has been received and applied.
2366+
/// </summary>
23482367
protected virtual void OnTransformUpdated()
23492368
{
23502369

@@ -2958,6 +2977,9 @@ protected virtual void OnNetworkTransformStateUpdated(ref NetworkTransformState
29582977

29592978
}
29602979

2980+
/// <summary>
2981+
/// Virtual method that is invoked on the non-authority side when a state update has been recieved but not yet applied.
2982+
/// </summary>
29612983
protected virtual void OnBeforeUpdateTransformState()
29622984
{
29632985

@@ -3516,6 +3538,7 @@ public override void OnGainedOwnership()
35163538
base.OnGainedOwnership();
35173539
}
35183540

3541+
/// <inheritdoc/>
35193542
protected override void OnOwnershipChanged(ulong previous, ulong current)
35203543
{
35213544
// If we were the previous owner or the newly assigned owner then reinitialize
@@ -4108,6 +4131,7 @@ internal static float GetTickLatency(NetworkManager networkManager)
41084131
/// <remarks>
41094132
/// Only valid on clients.
41104133
/// </remarks>
4134+
/// <returns>Returns the tick latency and local offset in seconds and as a float value.</returns>
41114135
public static float GetTickLatency()
41124136
{
41134137
return GetTickLatency(NetworkManager.Singleton);
@@ -4125,6 +4149,7 @@ internal static float GetTickLatencyInSeconds(NetworkManager networkManager)
41254149
/// <summary>
41264150
/// Returns the tick latency in seconds (typically fractional)
41274151
/// </summary>
4152+
/// <returns>Returns the current tick latency in seconds as a float value.</returns>
41284153
public static float GetTickLatencyInSeconds()
41294154
{
41304155
return GetTickLatencyInSeconds(NetworkManager.Singleton);

pvpExceptions.json

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,6 @@
4545
"Unity.Netcode.Components.NetworkDeltaPosition: void NetworkSerialize(BufferSerializer<T>): missing <typeparam name=\"T\">",
4646
"Unity.Netcode.Components.NetworkDeltaPosition: Vector3 GetConvertedDelta(): missing <returns>",
4747
"Unity.Netcode.Components.NetworkDeltaPosition: Vector3 GetDeltaPosition(): missing <returns>",
48-
"Unity.Netcode.Components.NetworkTransform: AuthorityMode: undocumented",
49-
"Unity.Netcode.Components.NetworkTransform: PositionInLocalSpace: undocumented",
50-
"Unity.Netcode.Components.NetworkTransform: RotationInLocalSpace: undocumented",
51-
"Unity.Netcode.Components.NetworkTransform: void OnTransformUpdated(): undocumented",
52-
"Unity.Netcode.Components.NetworkTransform: void OnBeforeUpdateTransformState(): undocumented",
53-
"Unity.Netcode.Components.NetworkTransform: void OnOwnershipChanged(ulong, ulong): undocumented",
54-
"Unity.Netcode.Components.NetworkTransform: float GetTickLatency(): missing <returns>",
55-
"Unity.Netcode.Components.NetworkTransform: float GetTickLatencyInSeconds(): missing <returns>",
56-
"Unity.Netcode.Components.NetworkTransform.NetworkTransformState: bool IsUnreliableFrameSync(): missing <returns>",
57-
"Unity.Netcode.Components.NetworkTransform.NetworkTransformState: bool IsReliableStateUpdate(): missing <returns>",
58-
"Unity.Netcode.Components.NetworkTransform.NetworkTransformState: void NetworkSerialize(BufferSerializer<T>): missing <param name=\"serializer\">",
59-
"Unity.Netcode.Components.NetworkTransform.NetworkTransformState: void NetworkSerialize(BufferSerializer<T>): missing <typeparam name=\"T\">",
60-
"Unity.Netcode.Components.NetworkTransform.AuthorityModes: undocumented",
61-
"Unity.Netcode.Components.NetworkTransform.AuthorityModes: Server: undocumented",
62-
"Unity.Netcode.Components.NetworkTransform.AuthorityModes: Owner: undocumented",
6348
"Unity.Netcode.NetworkConfig: Prefabs: undocumented",
6449
"Unity.Netcode.NetworkConfig: NetworkTopology: undocumented",
6550
"Unity.Netcode.NetworkConfig: UseCMBService: undocumented",

0 commit comments

Comments
 (0)