Skip to content

Commit ced4384

Browse files
michalChrobotNoelStephensUnityEmandMunity-renovate[bot]
authored
docs: [1.X] fixes of PVP exceptions (#3300)
This PR focuses on fixing PVP errors related to PVP-151-1 "**_Public APIs should be documented_**" and all remaining PVP errors **present in pvpExceptions.json file** We have quite a lot of errors to address so this PR will be a collaborative effort. If anyone want's to add to it what we should do is: 1. Check errors present in pvpExceptions.json file (preferably under "PVP-150-1", choose some to fix 2. Address those errors and when making commit remove the fixed errors from pvpExceptions file The first commit of this PR is an example of how such process should look like In general [new CI implementation](#3193) will catch all new errors like this so all we need to do is fix the present ones. This PR **does not** focus on PVP present in gold profile but if capacity allows, those can also be addressed. **Error present in "PVP-41-1" is to be expected** so there is no need of fixing this one! Another thing is that we could ignore error related to missing APIs for RuntimeTests because those were made internal in 2.X version (that's why those errors are not popping by there). Those APIs are not user facing so we could just leave them (otherwise there is like 2000 more APIs to add) --------- Co-authored-by: Noel Stephens <[email protected]> Co-authored-by: Emma <[email protected]> Co-authored-by: unity-renovate[bot] <120015202+unity-renovate[bot]@users.noreply.github.com>
1 parent 12dd5bd commit ced4384

18 files changed

+512
-350
lines changed

.yamato/wrench/package-pack-jobs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ package_pack_-_netcode_gameobjects:
2626
Job Maintainers: '#rm-packageworks'
2727
Wrench: 0.10.44.0
2828

29+

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,24 @@ namespace Unity.Netcode.Components
4646
[DefaultExecutionOrder(100000)] // this is needed to catch the update time after the transform was updated by user scripts
4747
public class AnticipatedNetworkTransform : NetworkTransform
4848
{
49+
/// <summary>
50+
/// Represents the state of a transform, including position, rotation, and scale.
51+
/// </summary>
4952
public struct TransformState
5053
{
54+
/// <summary>
55+
/// The position of the transform.
56+
/// </summary>
5157
public Vector3 Position;
58+
59+
/// <summary>
60+
/// The rotation of the transform.
61+
/// </summary>
5262
public Quaternion Rotation;
63+
64+
/// <summary>
65+
/// The scale of the transform.
66+
/// </summary>
5367
public Vector3 Scale;
5468
}
5569

@@ -242,6 +256,9 @@ public void AnticipateState(TransformState newState)
242256
m_CurrentSmoothTime = 0;
243257
}
244258

259+
/// <summary>
260+
/// Updates the AnticipatedNetworkTransform each frame.
261+
/// </summary>
245262
protected override void Update()
246263
{
247264
// If not spawned or this instance has authority, exit early
@@ -350,6 +367,13 @@ private void ResetAnticipatedState()
350367
m_CurrentSmoothTime = 0;
351368
}
352369

370+
/// <summary>
371+
/// Invoked when a new client joins (server and client sides).
372+
/// Server Side: Serializes as if we were teleporting (everything is sent via NetworkTransformState).
373+
/// Client Side: Adds the interpolated state which applies the NetworkTransformState as well.
374+
/// </summary>
375+
/// <typeparam name="T">The type of the serializer.</typeparam>
376+
/// <param name="serializer">The serializer used to serialize the state.</param>
353377
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
354378
{
355379
base.OnSynchronize(ref serializer);
@@ -361,6 +385,9 @@ protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
361385
}
362386
}
363387

388+
/// <summary>
389+
/// Invoked when the NetworkObject is spawned.
390+
/// </summary>
364391
public override void OnNetworkSpawn()
365392
{
366393
base.OnNetworkSpawn();
@@ -373,6 +400,9 @@ public override void OnNetworkSpawn()
373400
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
374401
}
375402

403+
/// <summary>
404+
/// Invoked when the NetworkObject is despawned.
405+
/// </summary>
376406
public override void OnNetworkDespawn()
377407
{
378408
if (m_AnticipatedObject != null)
@@ -387,6 +417,9 @@ public override void OnNetworkDespawn()
387417
base.OnNetworkDespawn();
388418
}
389419

420+
/// <summary>
421+
/// Invoked when the NetworkObject is destroyed.
422+
/// </summary>
390423
public override void OnDestroy()
391424
{
392425
if (m_AnticipatedObject != null)
@@ -438,19 +471,30 @@ public void Smooth(TransformState from, TransformState to, float durationSeconds
438471
m_CurrentSmoothTime = 0;
439472
}
440473

474+
/// <summary>
475+
/// Invoked just before the authoritative state is updated and pushed to non-authoritative instances.
476+
/// </summary>
441477
protected override void OnBeforeUpdateTransformState()
442478
{
443479
// this is called when new data comes from the server
444480
m_LastAuthorityUpdateCounter = NetworkManager.AnticipationSystem.LastAnticipationAck;
445481
m_OutstandingAuthorityChange = true;
446482
}
447483

484+
/// <summary>
485+
/// Invoked when the NetworkTransform state is updated.
486+
/// </summary>
487+
/// <param name="oldState">The previous state of the NetworkTransform.</param>
488+
/// <param name="newState">The new state of the NetworkTransform.</param>
448489
protected override void OnNetworkTransformStateUpdated(ref NetworkTransformState oldState, ref NetworkTransformState newState)
449490
{
450491
base.OnNetworkTransformStateUpdated(ref oldState, ref newState);
451492
ApplyAuthoritativeState();
452493
}
453494

495+
/// <summary>
496+
/// Invoked whenever the transform has been updated.
497+
/// </summary>
454498
protected override void OnTransformUpdated()
455499
{
456500
if (CanCommitToTransform || m_AnticipatedObject == null)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ private void SerializeRead(FastBufferReader reader)
7777
/// <summary>
7878
/// The serialization implementation of <see cref="INetworkSerializable"/>.
7979
/// </summary>
80+
/// <typeparam name="T">The type of the serializer.</typeparam>
81+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
8082
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
8183
{
8284
if (serializer.IsReader)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ private void SerializeRead(FastBufferReader reader)
6161
/// <summary>
6262
/// The serialization implementation of <see cref="INetworkSerializable"/>.
6363
/// </summary>
64+
/// <typeparam name="T">The type of the serializer.</typeparam>
65+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
6466
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
6567
{
6668
if (serializer.IsReader)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ public struct NetworkDeltaPosition : INetworkSerializable
3030
/// <summary>
3131
/// The serialization implementation of <see cref="INetworkSerializable"/>
3232
/// </summary>
33+
/// <typeparam name="T">The type of the serializer.</typeparam>
34+
/// <param name="serializer">The serializer used to serialize or deserialize the state.</param>
3335
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
3436
{
3537
if (!SynchronizeBase)
@@ -105,6 +107,7 @@ public Vector3 GetFullPosition()
105107
/// <remarks>
106108
/// Only applies to the authoritative side for <see cref="NetworkTransform"/> instances.
107109
/// </remarks>
110+
/// <returns>The current delta position as a <see cref="Vector3"/> with half float precision.</returns>
108111
[MethodImpl(MethodImplOptions.AggressiveInlining)]
109112
public Vector3 GetConvertedDelta()
110113
{
@@ -120,6 +123,7 @@ public Vector3 GetConvertedDelta()
120123
/// Precision loss adjustments are one network tick behind on the
121124
/// non-authoritative side.
122125
/// </remarks>
126+
/// <returns>The current delta position as a <see cref="Vector3"/>.</returns>
123127
[MethodImpl(MethodImplOptions.AggressiveInlining)]
124128
public Vector3 GetDeltaPosition()
125129
{

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

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class NetworkTransform : NetworkBehaviour
6666
/// - The teleporting state update.
6767
/// - When using half float precision and the `NetworkDeltaPosition` delta exceeds the maximum delta forcing the axis in
6868
/// question to be collapsed into the core base position, this state update will be sent as reliable fragmented sequenced.
69-
///
69+
///
7070
/// In order to preserve a continual consistency of axial values when unreliable delta messaging is enabled (due to the
7171
/// possibility of dropping packets), NetworkTransform instances will send 1 axial frame synchronization update per
7272
/// second (only for the axis marked to synchronize are sent as reliable fragmented sequenced) as long as a delta state
@@ -104,7 +104,7 @@ public struct NetworkTransformState : INetworkSerializable
104104
private const int k_ReliableSequenced = 0x00080000;
105105
private const int k_UseUnreliableDeltas = 0x00100000;
106106
private const int k_UnreliableFrameSync = 0x00200000;
107-
private const int k_TrackStateId = 0x10000000; // (Internal Debugging) When set each state update will contain a state identifier
107+
private const int k_TrackStateId = 0x10000000; // (Internal Debugging) When set each state update will contain a state identifier
108108

109109
// Stores persistent and state relative flags
110110
private uint m_Bitset;
@@ -459,10 +459,11 @@ internal set
459459
}
460460

461461
/// <summary>
462-
/// Returns whether this state update was a frame synchronization when
463-
/// UseUnreliableDeltas is enabled. When set, the entire transform will
462+
/// Returns whether this state update was a frame synchronization when
463+
/// UseUnreliableDeltas is enabled. When set, the entire transform will
464464
/// be or has been synchronized.
465465
/// </summary>
466+
/// <returns><see cref="true"/> if this state update was a frame synchronization; otherwise, <see cref="false"/>.</returns>
466467
public bool IsUnreliableFrameSync()
467468
{
468469
return UnreliableFrameSync;
@@ -475,6 +476,7 @@ public bool IsUnreliableFrameSync()
475476
/// <remarks>
476477
/// Unreliable delivery will only be used if <see cref="UseUnreliableDeltas"/> is set.
477478
/// </remarks>
479+
/// <returns><see cref="true"/> if this state was sent with reliable delivery; otherwise, <see cref="false"/>.</returns>
478480
public bool IsReliableStateUpdate()
479481
{
480482
return ReliableSequenced;
@@ -586,7 +588,7 @@ public Quaternion GetRotation()
586588
/// <remarks>
587589
/// When there is no change in an updated state's position then there are no values to return.
588590
/// Checking for <see cref="HasPositionChange"/> is one way to detect this.
589-
/// When used with half precision it returns the half precision delta position state update
591+
/// When used with half precision it returns the half precision delta position state update
590592
/// which will not be the full position.
591593
/// To get a NettworkTransform's full position, use <see cref="GetSpaceRelativePosition(bool)"/> and
592594
/// pass true as the parameter.
@@ -661,6 +663,8 @@ public int GetNetworkTick()
661663
/// <summary>
662664
/// Serializes this <see cref="NetworkTransformState"/>
663665
/// </summary>
666+
/// <typeparam name="T">The type of the serializer.</typeparam>
667+
/// <param name="serializer">The serializer used for reading or writing the state.</param>
664668
public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReaderWriter
665669
{
666670
// Used to calculate the LastSerializedSize value
@@ -897,7 +901,7 @@ public void NetworkSerialize<T>(BufferSerializer<T> serializer) where T : IReade
897901
if (HasScaleChange)
898902
{
899903
// If we are teleporting (which includes synchronizing) and the associated NetworkObject has a parent
900-
// then we want to serialize the LossyScale since NetworkObject spawn order is not guaranteed
904+
// then we want to serialize the LossyScale since NetworkObject spawn order is not guaranteed
901905
if (IsTeleportingNextFrame && IsParented)
902906
{
903907
serializer.SerializeValue(ref LossyScale);
@@ -1419,9 +1423,8 @@ private bool ShouldSynchronizeHalfFloat(ulong targetClientId)
14191423
/// <remarks>
14201424
/// If a derived class overrides this, then make sure to invoke this base method!
14211425
/// </remarks>
1422-
/// <typeparam name="T"></typeparam>
1423-
/// <param name="serializer"></param>
1424-
/// <param name="targetClientId">the clientId being synchronized (both reading and writing)</param>
1426+
/// <typeparam name="T">The type of the serializer.</typeparam>
1427+
/// <param name="serializer">The serializer used for reading or writing the state.</param>
14251428
protected override void OnSynchronize<T>(ref BufferSerializer<T> serializer)
14261429
{
14271430
m_CachedNetworkManager = NetworkManager;
@@ -1575,11 +1578,11 @@ private void TryCommitTransform(ref Transform transformToCommit, bool synchroniz
15751578
Debug.LogException(ex);
15761579
}
15771580

1578-
// The below is part of assuring we only send a frame synch, when sending unreliable deltas, if
1581+
// The below is part of assuring we only send a frame synch, when sending unreliable deltas, if
15791582
// we have already sent at least one unreliable delta state update. At this point in the callstack,
15801583
// a delta state update has just been sent in the above UpdateTransformState() call and as long as
15811584
// we didn't send a frame synch and we are not synchronizing then we know at least one unreliable
1582-
// delta has been sent. Under this scenario, we should start checking for this instance's alloted
1585+
// delta has been sent. Under this scenario, we should start checking for this instance's alloted
15831586
// frame synch "tick slot". Once we send a frame synch, if no other deltas occur after that
15841587
// (i.e. the object is at rest) then we will stop sending frame synch's until the object begins
15851588
// moving, rotating, or scaling again.
@@ -1862,7 +1865,7 @@ private bool ApplyTransformToNetworkStateWithInfo(ref NetworkTransformState netw
18621865

18631866
networkState.NetworkDeltaPosition = m_HalfPositionState;
18641867

1865-
// If ownership offset is greater or we are doing an axial synchronization then synchronize the base position
1868+
// If ownership offset is greater or we are doing an axial synchronization then synchronize the base position
18661869
if ((m_HalfFloatTargetTickOwnership > m_CachedNetworkManager.ServerTime.Tick || isAxisSync) && !networkState.IsTeleportingNextFrame)
18671870
{
18681871
networkState.SynchronizeBaseHalfFloat = true;
@@ -2056,6 +2059,10 @@ private bool ApplyTransformToNetworkStateWithInfo(ref NetworkTransformState netw
20562059
return isDirty;
20572060
}
20582061

2062+
/// <summary>
2063+
/// Invoked whenever the transform has been updated.
2064+
/// This method can be overridden to handle any custom logic that needs to occur after the transform has been updated.
2065+
/// </summary>
20592066
protected virtual void OnTransformUpdated()
20602067
{
20612068

@@ -2602,6 +2609,10 @@ protected virtual void OnNetworkTransformStateUpdated(ref NetworkTransformState
26022609

26032610
}
26042611

2612+
/// <summary>
2613+
/// Invoked just before the transform state is updated.
2614+
/// This method can be overridden to handle any custom logic that needs to occur before the transform state is updated.
2615+
/// </summary>
26052616
protected virtual void OnBeforeUpdateTransformState()
26062617
{
26072618

@@ -2816,6 +2827,12 @@ public override void OnGainedOwnership()
28162827
base.OnGainedOwnership();
28172828
}
28182829

2830+
/// <summary>
2831+
/// Invoked when the ownership of the <see cref="NetworkObject"/> changes.
2832+
/// This method handles reinitialization when the local client gains or loses ownership of the <see cref="NetworkObject"/>.
2833+
/// </summary>
2834+
/// <param name="previous">The client ID of the previous owner.</param>
2835+
/// <param name="current">The client ID of the new owner.</param>
28192836
protected override void OnOwnershipChanged(ulong previous, ulong current)
28202837
{
28212838
// If we were the previous owner or the newly assigned owner then reinitialize
@@ -2842,7 +2859,7 @@ protected virtual void OnInitialize(ref NetworkTransformState replicatedState)
28422859
/// This method is only invoked by the owner
28432860
/// Use: OnInitialize(ref NetworkTransformState replicatedState) to be notified on all instances
28442861
/// </summary>
2845-
/// <param name="replicatedState"></param>
2862+
/// <param name="replicatedState">The current <see cref="NetworkVariable{NetworkTransformState}"/> after initializing.</param>
28462863
protected virtual void OnInitialize(ref NetworkVariable<NetworkTransformState> replicatedState)
28472864
{
28482865

@@ -2851,9 +2868,9 @@ protected virtual void OnInitialize(ref NetworkVariable<NetworkTransformState> r
28512868
private int m_HalfFloatTargetTickOwnership;
28522869

28532870
/// <summary>
2854-
/// The internal initialzation method to allow for internal API adjustments
2871+
/// The internal initialization method to allow for internal API adjustments
28552872
/// </summary>
2856-
/// <param name="isOwnershipChange"></param>
2873+
/// <param name="isOwnershipChange">Indicates whether the initialization is due to an ownership change.</param>
28572874
private void InternalInitialization(bool isOwnershipChange = false)
28582875
{
28592876
if (!IsSpawned)
@@ -2956,11 +2973,11 @@ public override void OnNetworkObjectParentChanged(NetworkObject parentNetworkObj
29562973
/// The parameters are broken up into pos / rot / scale on purpose so that the caller can perturb
29572974
/// just the desired one(s)
29582975
/// </summary>
2959-
/// <param name="posIn"></param> new position to move to. Can be null
2960-
/// <param name="rotIn"></param> new rotation to rotate to. Can be null
2976+
/// <param name="posIn">new position to move to. Can be null.</param>
2977+
/// <param name="rotIn">new rotation to rotate to. Can be null.</param>
29612978
/// <param name="scaleIn">new scale to scale to. Can be null</param>
29622979
/// <param name="teleportDisabled">When true (the default) the <see cref="NetworkObject"/> will not be teleported and, if enabled, will interpolate. When false the <see cref="NetworkObject"/> will teleport/apply the parameters provided immediately.</param>
2963-
/// <exception cref="Exception"></exception>
2980+
/// <exception cref="Exception">Thrown when the function is called on non-spawned object or, when it's called without proper authority</exception>
29642981
public void SetState(Vector3? posIn = null, Quaternion? rotIn = null, Vector3? scaleIn = null, bool teleportDisabled = true)
29652982
{
29662983
if (!IsSpawned)
@@ -3023,7 +3040,7 @@ private void SetStateInternal(Vector3 pos, Quaternion rot, Vector3 scale, bool s
30233040

30243041
var transformToCommit = transform;
30253042

3026-
// Explicit set states are cumulative during a fractional tick period of time (i.e. each SetState invocation will
3043+
// Explicit set states are cumulative during a fractional tick period of time (i.e. each SetState invocation will
30273044
// update the axial deltas to whatever changes are applied). As such, we need to preserve the dirty and explicit
30283045
// state flags.
30293046
var stateWasDirty = m_LocalAuthoritativeNetworkState.IsDirty;
@@ -3111,7 +3128,9 @@ private void UpdateInterpolation()
31113128
}
31123129
}
31133130

3114-
/// <inheritdoc/>
3131+
/// <summary>
3132+
/// This method is called once per frame.
3133+
/// </summary>
31153134
/// <remarks>
31163135
/// If you override this method, be sure that:
31173136
/// - Non-authority always invokes this base class method.
@@ -3134,10 +3153,10 @@ protected virtual void Update()
31343153
/// <summary>
31353154
/// Teleport the transform to the given values without interpolating
31363155
/// </summary>
3137-
/// <param name="newPosition"></param> new position to move to.
3138-
/// <param name="newRotation"></param> new rotation to rotate to.
3156+
/// <param name="newPosition">new position to move to.</param>
3157+
/// <param name="newRotation">new rotation to rotate to.</param>
31393158
/// <param name="newScale">new scale to scale to.</param>
3140-
/// <exception cref="Exception"></exception>
3159+
/// <exception cref="Exception">Thrown if teleporting is attempted on a non-authoritative side.</exception>
31413160
public void Teleport(Vector3 newPosition, Quaternion newRotation, Vector3 newScale)
31423161
{
31433162
if (!CanCommitToTransform)

0 commit comments

Comments
 (0)