From 7a95a1001b260adbad83f2b2a6742096002ca0cb Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 1 Apr 2025 10:53:26 +0200 Subject: [PATCH 01/16] Initial PR to separate Test stuff from Missing API description --- pvpExceptions.json | 1 + 1 file changed, 1 insertion(+) diff --git a/pvpExceptions.json b/pvpExceptions.json index 0a338d445a..5bcda0770f 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -108,6 +108,7 @@ "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", "Unity.Netcode.Transports.UTP.UnityTransport.ConnectionAddressData: IsIpv6: undocumented", + "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: void OnNetworkSpawn(): undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: void RegisterAndLabelNetworkObject(): undocumented", From 96cb8d8e6b16276fa75ad2695eaa2434fa777757 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:16:34 +0200 Subject: [PATCH 02/16] 150-1 PVP fixes --- .../TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs | 1 - .../Runtime/Components/BufferDataValidationComponent.cs | 1 - .../NetworkVariableBaseInitializesWhenPersisted.cs | 1 + pvpExceptions.json | 8 -------- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs index 3669c36f16..d09736a387 100644 --- a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs +++ b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs @@ -425,7 +425,6 @@ private static void SceneManagerValidationAndTestRunnerInitialization(NetworkMan /// The Server NetworkManager /// The Clients NetworkManager /// called immediately after server is started and before client(s) are started - /// public static bool Start(bool host, NetworkManager server, NetworkManager[] clients, BeforeClientStartCallback callback = null) { if (s_IsStarted) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs index 3912448423..0e2b7fd869 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs @@ -54,7 +54,6 @@ private void Start() /// /// Returns back whether the test has completed the total number of iterations /// - /// public bool IsTestComplete() { if (m_CurrentBufferSize > MaximumBufferSize || TestFailed) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs index 2a9a1b052e..2ce7186db6 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs @@ -334,6 +334,7 @@ public void Initialize(NetworkManager networkManager) /// /// This validates that the instances persisted to the next test set and persisted /// between network sessions + /// public bool ValidateInstanceSpawnCount(int minCount) { // First pass we should have no instances diff --git a/pvpExceptions.json b/pvpExceptions.json index 5bcda0770f..6d63494d65 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -10,14 +10,6 @@ "Failed to find a suitable OpenCL device, baking cannot use GPU lightmapper." ] }, - "PVP-150-1": { - "errors": [ - "Unity.Netcode.TestHelpers.Runtime.NetcodeIntegrationTestHelpers: bool Start(bool, NetworkManager, NetworkManager[], BeforeClientStartCallback): empty tag", - "Unity.Netcode.TestHelpers.Runtime.NetcodeIntegrationTestHelpers: IEnumerator WaitForClientsConnected(NetworkManager[], ResultWrapper, float): XML is not well-formed: An identifier was expected", - "Unity.Netcode.RuntimeTests.BufferDataValidationComponent: bool IsTestComplete(): empty tag", - "Unity.Netcode.RuntimeTests.NetworkVariableBaseInitializesWhenPersisted.PrefabInstanceHandler: bool ValidateInstanceSpawnCount(int): XML is not well-formed: Expected an end tag for element 'summary'" - ] - }, "PVP-151-1": { "errors": [ "Unity.Netcode.NetworkConfig: Prefabs: undocumented", From 6d9bf0dbf2a181f1c19506015bf49f898ea4b492 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Mon, 7 Apr 2025 15:05:12 +0200 Subject: [PATCH 03/16] NetworkPrefab and NetworkPrefabs corrections --- .../Runtime/Configuration/NetworkPrefab.cs | 26 +++++++++++++++++++ .../Runtime/Configuration/NetworkPrefabs.cs | 8 ++++++ 2 files changed, 34 insertions(+) diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs index 9cc2158cc1..c101104269 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs @@ -57,6 +57,11 @@ public class NetworkPrefab /// public GameObject OverridingTargetPrefab; + /// + /// Compares this NetworkPrefab with another to determine equality + /// + /// The NetworkPrefab to compare against + /// True if all fields match between the two NetworkPrefabs, false otherwise public bool Equals(NetworkPrefab other) { return Override == other.Override && @@ -66,6 +71,12 @@ public bool Equals(NetworkPrefab other) OverridingTargetPrefab == other.OverridingTargetPrefab; } + /// + /// Gets the GlobalObjectIdHash of the source prefab based on the current override settings + /// + /// The hash value identifying the source prefab + /// Thrown when required prefab references are missing or invalid + /// Thrown when Override has an invalid value public uint SourcePrefabGlobalObjectIdHash { get @@ -98,6 +109,12 @@ public uint SourcePrefabGlobalObjectIdHash } } + /// + /// Gets the GlobalObjectIdHash of the target prefab when using prefab overrides + /// + /// The hash value identifying the target prefab, or 0 if no override is set + /// Thrown when required prefab references are missing or invalid + /// Thrown when Override has an invalid value public uint TargetPrefabGlobalObjectIdHash { get @@ -122,6 +139,11 @@ public uint TargetPrefabGlobalObjectIdHash } } + /// + /// Validates the NetworkPrefab configuration to ensure all required fields are properly set + /// + /// Optional index used for error reporting when validating lists of prefabs + /// True if the NetworkPrefab is valid and ready for use, false otherwise public bool Validate(int index = -1) { NetworkObject networkObject; @@ -224,6 +246,10 @@ public bool Validate(int index = -1) return true; } + /// + /// Returns a string representation of this NetworkPrefab's source and target hash values + /// + /// A string containing the source and target hash values public override string ToString() { return $"{{SourceHash: {SourceHashToOverride}, TargetHash: {TargetPrefabGlobalObjectIdHash}}}"; diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs index 42758f7e78..26a33ce1b8 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs @@ -39,6 +39,9 @@ public class NetworkPrefabs [NonSerialized] public Dictionary OverrideToNetworkPrefab = new Dictionary(); + /// + /// Gets the read-only list of all registered network prefabs + /// public IReadOnlyList Prefabs => m_Prefabs; [NonSerialized] @@ -84,6 +87,7 @@ internal void Shutdown() /// Processes the if one is present for use during runtime execution, /// else processes . /// + /// /// When true, logs warnings about invalid prefabs that are removed during initialization public void Initialize(bool warnInvalid = true) { m_Prefabs.Clear(); @@ -156,6 +160,8 @@ public void Initialize(bool warnInvalid = true) /// /// Add a new NetworkPrefab instance to the list /// + /// The NetworkPrefab to add + /// True if the prefab was successfully added, false if it was invalid or already registered /// /// The framework does not synchronize this list between clients. Any runtime changes must be handled manually. /// @@ -177,6 +183,7 @@ public bool Add(NetworkPrefab networkPrefab) /// /// Remove a NetworkPrefab instance from the list /// + /// The NetworkPrefab to remove /// /// The framework does not synchronize this list between clients. Any runtime changes must be handled manually. /// @@ -199,6 +206,7 @@ public void Remove(NetworkPrefab prefab) /// /// Remove a NetworkPrefab instance with matching from the list /// + /// The GameObject to match against for removal /// /// The framework does not synchronize this list between clients. Any runtime changes must be handled manually. /// From 0fedf0cf96467d05ce2db993754e07381ddff64a Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:23:34 +0200 Subject: [PATCH 04/16] The rest of NetworkPrefab APIs --- .../Runtime/Configuration/NetworkPrefabs.cs | 5 ++++- pvpExceptions.json | 14 +------------- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs index 26a33ce1b8..6e801f5b61 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefabs.cs @@ -65,6 +65,9 @@ private void RemoveTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab) m_Prefabs.Remove(networkPrefab); } + /// + /// Finalizer that ensures proper cleanup of network prefab resources + /// ~NetworkPrefabs() { Shutdown(); @@ -87,7 +90,7 @@ internal void Shutdown() /// Processes the if one is present for use during runtime execution, /// else processes . /// - /// /// When true, logs warnings about invalid prefabs that are removed during initialization + /// When true, logs warnings about invalid prefabs that are removed during initialization public void Initialize(bool warnInvalid = true) { m_Prefabs.Clear(); diff --git a/pvpExceptions.json b/pvpExceptions.json index 6d63494d65..2f603b040c 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -12,19 +12,7 @@ }, "PVP-151-1": { "errors": [ - "Unity.Netcode.NetworkConfig: Prefabs: undocumented", - "Unity.Netcode.NetworkPrefab: bool Equals(NetworkPrefab): undocumented", - "Unity.Netcode.NetworkPrefab: SourcePrefabGlobalObjectIdHash: undocumented", - "Unity.Netcode.NetworkPrefab: TargetPrefabGlobalObjectIdHash: undocumented", - "Unity.Netcode.NetworkPrefab: bool Validate(int): undocumented", - "Unity.Netcode.NetworkPrefab: string ToString(): undocumented", - "Unity.Netcode.NetworkPrefabs: Prefabs: undocumented", - "Unity.Netcode.NetworkPrefabs: void Finalize(): undocumented", - "Unity.Netcode.NetworkPrefabs: void Initialize(bool): missing ", - "Unity.Netcode.NetworkPrefabs: bool Add(NetworkPrefab): missing ", - "Unity.Netcode.NetworkPrefabs: bool Add(NetworkPrefab): missing ", - "Unity.Netcode.NetworkPrefabs: void Remove(NetworkPrefab): missing ", - "Unity.Netcode.NetworkPrefabs: void Remove(GameObject): missing ", + "Unity.Netcode.NetworkConfig: Prefabs: undocumented", "Unity.Netcode.ConnectionEventData: EventType: undocumented", "Unity.Netcode.RpcException: undocumented", "Unity.Netcode.RpcException: .ctor(string): undocumented", From 40c6e58c3f1ac2af65b13f11c776d5e85f5b1687 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Mon, 7 Apr 2025 14:54:39 +0200 Subject: [PATCH 05/16] AnticipatedNetworkVariable corrected --- .../AnticipatedNetworkVariable.cs | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs index 94625722e3..b53ce853e5 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs @@ -4,10 +4,21 @@ namespace Unity.Netcode { - + /// + /// Defines how anticipated network variables handle authoritative updates that are older than the current anticipated state + /// public enum StaleDataHandling { + /// + /// Ignores authoritative updates that are older than the current anticipated state. + /// The anticipated value will not be replaced until a newer authoritative update is received. + /// Ignore, + + /// + /// Applies authoritative updates even if they are older than the current anticipated state. + /// This triggers reanticipation to calculate a new anticipated value based on the authoritative state. + /// Reanticipate } @@ -85,6 +96,12 @@ public class AnticipatedNetworkVariable : NetworkVariableBase #pragma warning restore IDE0001 public StaleDataHandling StaleDataHandling; + /// + /// Delegate for handling changes in the authoritative value + /// + /// The network variable that changed + /// The previous value before the change + /// The new value after the change public delegate void OnAuthoritativeValueChangedDelegate(AnticipatedNetworkVariable variable, in T previousValue, in T newValue); /// @@ -121,6 +138,9 @@ public void ResetAnticipation() private AnticipatedObject m_AnticipatedObject; + /// + /// Initializes the network variable, setting up initial values and registering with the anticipation system + /// public override void OnInitialize() { m_AuthoritativeValue.Initialize(m_NetworkBehaviour); @@ -133,6 +153,10 @@ public override void OnInitialize() } } + /// + /// Checks if the current value has changed enough from its last synchronized value to warrant a new network update + /// + /// True if the value should be synchronized, false otherwise public override bool ExceedsDirtinessThreshold() { return m_AuthoritativeValue.ExceedsDirtinessThreshold(); @@ -227,6 +251,10 @@ public T AuthoritativeValue /// See , , , and so on /// for examples. /// + /// The authoritative value to interpolate from + /// The anticipated value to interpolate to + /// The interpolation factor between 0 and 1 + /// The interpolated value public delegate T SmoothDelegate(T authoritativeValue, T anticipatedValue, float amount); private SmoothDelegate m_SmoothDelegate = null; @@ -242,6 +270,9 @@ public AnticipatedNetworkVariable(T value = default, }; } + /// + /// Updates the smooth interpolation state if active + /// public void Update() { if (m_CurrentSmoothTime < m_SmoothDuration) @@ -253,6 +284,9 @@ public void Update() } } + /// + /// Releases all resources used by this network variable + /// public override void Dispose() { if (m_IsDisposed) @@ -357,26 +391,45 @@ public void Smooth(in T from, in T to, float durationSeconds, SmoothDelegate how m_HasSmoothValues = true; } + /// + /// Checks if the variable has been modified since the last network synchronization + /// + /// True if the variable needs to be synchronized, false otherwise public override bool IsDirty() { return m_AuthoritativeValue.IsDirty(); } + /// + /// Resets the dirty state after network synchronization + /// public override void ResetDirty() { m_AuthoritativeValue.ResetDirty(); } + /// + /// Writes only the changes in the variable's value to the network stream + /// + /// Buffer to write the delta to public override void WriteDelta(FastBufferWriter writer) { m_AuthoritativeValue.WriteDelta(writer); } + /// + /// Writes the complete state of the variable to the network stream + /// + /// Buffer to write the field to public override void WriteField(FastBufferWriter writer) { m_AuthoritativeValue.WriteField(writer); } + /// + /// Reads the complete state of the variable from the network stream + /// + /// Buffer to read the field from public override void ReadField(FastBufferReader reader) { m_AuthoritativeValue.ReadField(reader); @@ -384,6 +437,11 @@ public override void ReadField(FastBufferReader reader) NetworkVariableSerialization.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue); } + /// + /// Reads changes in the variable's value from the network stream + /// + /// Buffer to read the delta from + /// Whether to maintain the dirty state after reading public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) { m_AuthoritativeValue.ReadDelta(reader, keepDirtyDelta); From 0917354964cc990190f0c347191b972a8370aceb Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:26:11 +0200 Subject: [PATCH 06/16] pvpException file corrections after AnticipatedNetworkVariable changes --- pvpExceptions.json | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/pvpExceptions.json b/pvpExceptions.json index 2f603b040c..094ad41482 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -52,23 +52,6 @@ "Unity.Netcode.StaleDataHandling: undocumented", "Unity.Netcode.StaleDataHandling: Ignore: undocumented", "Unity.Netcode.StaleDataHandling: Reanticipate: undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void OnInitialize(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: bool ExceedsDirtinessThreshold(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: .ctor(T, StaleDataHandling): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void Update(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void Dispose(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void Finalize(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: bool IsDirty(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void ResetDirty(): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void WriteDelta(FastBufferWriter): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void WriteField(FastBufferWriter): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void ReadField(FastBufferReader): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable: void ReadDelta(FastBufferReader, bool): undocumented", - "Unity.Netcode.AnticipatedNetworkVariable.OnAuthoritativeValueChangedDelegate: undocumented", - "Unity.Netcode.AnticipatedNetworkVariable.SmoothDelegate: missing ", - "Unity.Netcode.AnticipatedNetworkVariable.SmoothDelegate: missing ", - "Unity.Netcode.AnticipatedNetworkVariable.SmoothDelegate: missing ", - "Unity.Netcode.AnticipatedNetworkVariable.SmoothDelegate: missing ", "Unity.Netcode.NetworkList: void Finalize(): undocumented", "Unity.Netcode.NetworkVariable: CheckExceedsDirtinessThreshold: undocumented", "Unity.Netcode.NetworkVariable: bool ExceedsDirtinessThreshold(): undocumented", From cdc75608085114b4f7489f89460a6d12a53e7166 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 10:49:42 +0200 Subject: [PATCH 07/16] NetworkVariable corrections and added inheritdocs when API is override --- .../AnticipatedNetworkVariable.cs | 34 ++++--------------- .../NetworkVariable/NetworkVariable.cs | 20 +++++++++++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs index b53ce853e5..fce8c058f0 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs @@ -284,9 +284,7 @@ public void Update() } } - /// - /// Releases all resources used by this network variable - /// + /// public override void Dispose() { if (m_IsDisposed) @@ -391,45 +389,31 @@ public void Smooth(in T from, in T to, float durationSeconds, SmoothDelegate how m_HasSmoothValues = true; } - /// - /// Checks if the variable has been modified since the last network synchronization - /// - /// True if the variable needs to be synchronized, false otherwise + /// public override bool IsDirty() { return m_AuthoritativeValue.IsDirty(); } - /// - /// Resets the dirty state after network synchronization - /// + /// public override void ResetDirty() { m_AuthoritativeValue.ResetDirty(); } - /// - /// Writes only the changes in the variable's value to the network stream - /// - /// Buffer to write the delta to + /// public override void WriteDelta(FastBufferWriter writer) { m_AuthoritativeValue.WriteDelta(writer); } - /// - /// Writes the complete state of the variable to the network stream - /// - /// Buffer to write the field to + /// public override void WriteField(FastBufferWriter writer) { m_AuthoritativeValue.WriteField(writer); } - /// - /// Reads the complete state of the variable from the network stream - /// - /// Buffer to read the field from + /// public override void ReadField(FastBufferReader reader) { m_AuthoritativeValue.ReadField(reader); @@ -437,11 +421,7 @@ public override void ReadField(FastBufferReader reader) NetworkVariableSerialization.Duplicate(m_AnticipatedValue, ref m_PreviousAnticipatedValue); } - /// - /// Reads changes in the variable's value from the network stream - /// - /// Buffer to read the delta from - /// Whether to maintain the dirty state after reading + /// public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) { m_AuthoritativeValue.ReadDelta(reader, keepDirtyDelta); diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs index 6d1d370316..b70084588e 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs @@ -22,10 +22,23 @@ public class NetworkVariable : NetworkVariableBase /// public OnValueChangedDelegate OnValueChanged; + /// + /// Delegate that determines if the difference between two values exceeds a threshold for network synchronization + /// + /// The previous value to compare against + /// The new value to compare + /// True if the difference exceeds the threshold and should be synchronized, false otherwise public delegate bool CheckExceedsDirtinessThresholdDelegate(in T previousValue, in T newValue); + /// + /// Delegate instance for checking if value changes exceed the dirtiness threshold + /// public CheckExceedsDirtinessThresholdDelegate CheckExceedsDirtinessThreshold; + /// + /// Determines if the current value has changed enough from its previous value to warrant network synchronization + /// + /// True if the value should be synchronized, false otherwise public override bool ExceedsDirtinessThreshold() { if (CheckExceedsDirtinessThreshold != null && m_HasPreviousValue) @@ -36,6 +49,9 @@ public override bool ExceedsDirtinessThreshold() return true; } + /// + /// Initializes the NetworkVariable by setting up initial and previous values + /// public override void OnInitialize() { base.OnInitialize(); @@ -171,6 +187,7 @@ internal ref T RefValue() return ref m_InternalValue; } + /// public override void Dispose() { if (m_IsDisposed) @@ -201,6 +218,9 @@ public override void Dispose() m_PreviousValue = default; } + /// + /// Finalizer that ensures proper cleanup of resources + /// ~NetworkVariable() { Dispose(); From 4aa8320e136f71f6553d1c9d24018f93558ed279 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:29:38 +0200 Subject: [PATCH 08/16] pvpExceptions update after cherry pick --- pvpExceptions.json | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pvpExceptions.json b/pvpExceptions.json index 094ad41482..3b6da38a30 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -53,13 +53,6 @@ "Unity.Netcode.StaleDataHandling: Ignore: undocumented", "Unity.Netcode.StaleDataHandling: Reanticipate: undocumented", "Unity.Netcode.NetworkList: void Finalize(): undocumented", - "Unity.Netcode.NetworkVariable: CheckExceedsDirtinessThreshold: undocumented", - "Unity.Netcode.NetworkVariable: bool ExceedsDirtinessThreshold(): undocumented", - "Unity.Netcode.NetworkVariable: void OnInitialize(): undocumented", - "Unity.Netcode.NetworkVariable: bool CheckDirtyState(bool): missing ", - "Unity.Netcode.NetworkVariable: void Dispose(): undocumented", - "Unity.Netcode.NetworkVariable: void Finalize(): undocumented", - "Unity.Netcode.NetworkVariable.CheckExceedsDirtinessThresholdDelegate: undocumented", "Unity.Netcode.NetworkVariableUpdateTraits: undocumented", "Unity.Netcode.NetworkVariableUpdateTraits: MinSecondsBetweenUpdates: undocumented", "Unity.Netcode.NetworkVariableUpdateTraits: MaxSecondsBetweenUpdates: undocumented", From 35dad813cfa037360724759420aa6db071f94d74 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Mon, 7 Apr 2025 14:30:33 +0200 Subject: [PATCH 09/16] RpcParams corrections --- .../Runtime/Messaging/RpcParams.cs | 57 ++++++++++++++++++- pvpExceptions.json | 12 ---- 2 files changed, 56 insertions(+), 13 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcParams.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcParams.cs index 7eb1a18009..b302e3f8f7 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcParams.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcParams.cs @@ -3,22 +3,54 @@ namespace Unity.Netcode { + /// + /// Specifies how RPC messages should be handled in terms of local execution timing + /// public enum LocalDeferMode { + /// + /// Uses the default behavior for RPC message handling + /// Default, + + /// + /// Defers the local execution of the RPC until the next network tick + /// Defer, + + /// + /// Executes the RPC immediately on the local client without waiting for network synchronization + /// SendImmediate } + /// - /// Generic RPC + /// Generic RPC. Defines parameters for sending Remote Procedure Calls (RPCs) in the network system /// public struct RpcSendParams { + /// + /// Specifies the target that will receive this RPC + /// public BaseRpcTarget Target; + /// + /// Controls how the RPC is handled for local execution timing + /// public LocalDeferMode LocalDeferMode; + /// + /// Implicitly converts a BaseRpcTarget to RpcSendParams + /// + /// The RPC target to convert + /// A new RpcSendParams instance with the specified target public static implicit operator RpcSendParams(BaseRpcTarget target) => new RpcSendParams { Target = target }; + + /// + /// Implicitly converts a LocalDeferMode to RpcSendParams + /// + /// The defer mode to convert + /// A new RpcSendParams instance with the specified defer mode public static implicit operator RpcSendParams(LocalDeferMode deferMode) => new RpcSendParams { LocalDeferMode = deferMode }; } @@ -51,9 +83,32 @@ public struct RpcParams /// public RpcReceiveParams Receive; + /// + /// Implicitly converts RpcSendParams to RpcParams + /// + /// The send parameters to convert + /// A new RpcParams instance with the specified send parameters public static implicit operator RpcParams(RpcSendParams send) => new RpcParams { Send = send }; + + /// + /// Implicitly converts a BaseRpcTarget to RpcParams + /// + /// The RPC target to convert + /// A new RpcParams instance with the specified target in its send parameters public static implicit operator RpcParams(BaseRpcTarget target) => new RpcParams { Send = new RpcSendParams { Target = target } }; + + /// + /// Implicitly converts a LocalDeferMode to RpcParams + /// + /// The defer mode to convert + /// A new RpcParams instance with the specified defer mode in its send parameters public static implicit operator RpcParams(LocalDeferMode deferMode) => new RpcParams { Send = new RpcSendParams { LocalDeferMode = deferMode } }; + + /// + /// Implicitly converts RpcReceiveParams to RpcParams + /// + /// The receive parameters to convert + /// A new RpcParams instance with the specified receive parameters public static implicit operator RpcParams(RpcReceiveParams receive) => new RpcParams { Receive = receive }; } diff --git a/pvpExceptions.json b/pvpExceptions.json index 3b6da38a30..ecf4211a49 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -37,18 +37,6 @@ "Unity.Netcode.ServerRpcAttribute: RequireOwnership: undocumented", "Unity.Netcode.ServerRpcAttribute: .ctor(): undocumented", "Unity.Netcode.ClientRpcAttribute: .ctor(): undocumented", - "Unity.Netcode.LocalDeferMode: undocumented", - "Unity.Netcode.LocalDeferMode: Default: undocumented", - "Unity.Netcode.LocalDeferMode: Defer: undocumented", - "Unity.Netcode.LocalDeferMode: SendImmediate: undocumented", - "Unity.Netcode.RpcSendParams: Target: undocumented", - "Unity.Netcode.RpcSendParams: LocalDeferMode: undocumented", - "Unity.Netcode.RpcSendParams: RpcSendParams op_Implicit(BaseRpcTarget): undocumented", - "Unity.Netcode.RpcSendParams: RpcSendParams op_Implicit(LocalDeferMode): undocumented", - "Unity.Netcode.RpcParams: RpcParams op_Implicit(RpcSendParams): undocumented", - "Unity.Netcode.RpcParams: RpcParams op_Implicit(BaseRpcTarget): undocumented", - "Unity.Netcode.RpcParams: RpcParams op_Implicit(LocalDeferMode): undocumented", - "Unity.Netcode.RpcParams: RpcParams op_Implicit(RpcReceiveParams): undocumented", "Unity.Netcode.StaleDataHandling: undocumented", "Unity.Netcode.StaleDataHandling: Ignore: undocumented", "Unity.Netcode.StaleDataHandling: Reanticipate: undocumented", From 86f224c5afb6dd2e306fb66e558a415f59550b84 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:35:28 +0200 Subject: [PATCH 10/16] NetworkTransport corrections --- .../Runtime/Transports/NetworkTransport.cs | 4 ++++ pvpExceptions.json | 4 ---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs index 7127279cda..eaa12089fe 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/NetworkTransport.cs @@ -28,6 +28,10 @@ public abstract class NetworkTransport : MonoBehaviour /// /// Delegate for transport network events /// + /// The type of network event that occurred + /// The ID of the client associated with this event + /// The data payload received with this event + /// The time when this event was received public delegate void TransportEventDelegate(NetworkEvent eventType, ulong clientId, ArraySegment payload, float receiveTime); /// diff --git a/pvpExceptions.json b/pvpExceptions.json index ecf4211a49..26975b166c 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -47,10 +47,6 @@ "Unity.Netcode.NetworkVariableBase: NetworkBehaviour GetBehaviour(): undocumented", "Unity.Netcode.NetworkVariableBase: void MarkNetworkBehaviourDirty(): undocumented", "Unity.Netcode.NetworkSceneManager: void SetClientSynchronizationMode(LoadSceneMode): XML is not well-formed: Expected an end tag for element 'summary'", - "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", - "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", - "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", - "Unity.Netcode.NetworkTransport.TransportEventDelegate: missing ", "Unity.Netcode.Transports.UTP.UnityTransport.ConnectionAddressData: IsIpv6: undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: undocumented", From ec8041d887ed534c74f553177109628e8cc33b60 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 13:48:27 +0200 Subject: [PATCH 11/16] Bunch of API additions --- .../Runtime/Messaging/CustomMessageManager.cs | 2 + .../Runtime/Messaging/RpcAttributes.cs | 43 +++++++++++++++++++ .../NetworkVariable/NetworkVariableBase.cs | 20 ++++++++- .../Runtime/Transports/UTP/UnityTransport.cs | 6 +++ pvpExceptions.json | 33 ++++---------- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs index 98c344fa19..d7b58ad977 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/CustomMessageManager.cs @@ -139,6 +139,8 @@ public void SendUnnamedMessage(ulong clientId, FastBufferWriter messageBuffer, N /// /// Delegate used to handle named messages /// + /// The client identifier of the message sender + /// The buffer containing the message data to be read public delegate void HandleNamedMessageDelegate(ulong senderClientId, FastBufferReader messagePayload); private Dictionary m_NamedMessageHandlers32 = new Dictionary(); diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs index acb6289b5b..39432097d4 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/RpcAttributes.cs @@ -25,11 +25,29 @@ public enum RpcDelivery public class RpcAttribute : Attribute { // Must match the set of parameters below + /// + /// Parameters that define the behavior of an RPC + /// public struct RpcAttributeParams { + /// + /// The delivery method for the RPC + /// public RpcDelivery Delivery; + + /// + /// When true, only the owner of the object can execute this RPC + /// public bool RequireOwnership; + + /// + /// When true, local execution of the RPC is deferred until the next network tick + /// public bool DeferLocal; + + /// + /// When true, allows the RPC target to be overridden at runtime + /// public bool AllowTargetOverride; } @@ -38,10 +56,26 @@ public struct RpcAttributeParams /// Type of RPC delivery method /// public RpcDelivery Delivery = RpcDelivery.Reliable; + + /// + /// When true, only the owner of the object can execute this RPC + /// public bool RequireOwnership; + + /// + /// When true, local execution of the RPC is deferred until the next network tick + /// public bool DeferLocal; + + /// + /// When true, allows the RPC target to be overridden at runtime + /// public bool AllowTargetOverride; + /// + /// Initializes a new instance of the RpcAttribute with the specified target + /// + /// The target for this RPC public RpcAttribute(SendTo target) { } @@ -60,8 +94,14 @@ private RpcAttribute() [AttributeUsage(AttributeTargets.Method)] public class ServerRpcAttribute : RpcAttribute { + /// + /// When true, only the owner of the NetworkObject can invoke this ServerRpc + /// public new bool RequireOwnership; + /// + /// Initializes a new instance of ServerRpcAttribute configured to target the server + /// public ServerRpcAttribute() : base(SendTo.Server) { @@ -75,6 +115,9 @@ public ServerRpcAttribute() : base(SendTo.Server) [AttributeUsage(AttributeTargets.Method)] public class ClientRpcAttribute : RpcAttribute { + /// + /// Initializes a new instance of ClientRpcAttribute configured to target all non-server clients + /// public ClientRpcAttribute() : base(SendTo.NotServer) { diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs index c6db156f81..a1d5623119 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs @@ -3,11 +3,20 @@ namespace Unity.Netcode { + /// + /// Defines timing constraints for network variable updates + /// public struct NetworkVariableUpdateTraits { + /// + /// The minimum amount of time that must pass between sending updates. If this amount of time has not passed since the last update, dirtiness will be ignored. + /// [Tooltip("The minimum amount of time that must pass between sending updates. If this amount of time has not passed since the last update, dirtiness will be ignored.")] public float MinSecondsBetweenUpdates; + /// + /// The maximum amount of time that a variable can be dirty without sending an update. If this amount of time has passed since the last update, an update will be sent even if the dirtiness threshold has not been met. + /// [Tooltip("The maximum amount of time that a variable can be dirty without sending an update. If this amount of time has passed since the last update, an update will be sent even if the dirtiness threshold has not been met.")] public float MaxSecondsBetweenUpdates; } @@ -40,6 +49,10 @@ public abstract class NetworkVariableBase : IDisposable // this NetworkVariableBase property instance will not update until the last session time used. internal bool HasBeenInitialized { get; private set; } + /// + /// Gets the NetworkBehaviour instance associated with this network variable + /// + /// The NetworkBehaviour that owns this network variable public NetworkBehaviour GetBehaviour() { return m_NetworkBehaviour; @@ -97,7 +110,7 @@ public void Initialize(NetworkBehaviour networkBehaviour) if (!m_NetworkBehaviour.NetworkObject.NetworkManagerOwner) { // Exit early if there has yet to be a NetworkManagerOwner assigned - // to the NetworkObject. This is ok because Initialize is invoked + // to the NetworkObject. This is ok because Initialize is invoked // multiple times until it is considered "initialized". return; } @@ -240,6 +253,9 @@ internal void UpdateLastSentTime() LastUpdateSent = m_NetworkBehaviour.NetworkManager.NetworkTimeSystem.LocalTime; } + /// + /// Marks the associated NetworkBehaviour as dirty, indicating it needs synchronization + /// protected void MarkNetworkBehaviourDirty() { if (m_NetworkBehaviour == null) @@ -374,7 +390,7 @@ internal ulong OwnerClientId() /// This should be always invoked (client & server) to assure the previous values are set /// !! IMPORTANT !! /// When a server forwards delta updates to connected clients, it needs to preserve the previous dirty value(s) - /// until it is done serializing all valid NetworkVariable field deltas (relative to each client). This is invoked + /// until it is done serializing all valid NetworkVariable field deltas (relative to each client). This is invoked /// after it is done forwarding the deltas at the end of the method. /// internal virtual void PostDeltaRead() diff --git a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs index 8a8afcdbac..3ba82432f4 100644 --- a/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs +++ b/com.unity.netcode.gameobjects/Runtime/Transports/UTP/UnityTransport.cs @@ -358,6 +358,12 @@ public NetworkEndpoint ListenEndPoint } } + /// + /// Gets whether the configured server address is an IPv6 address + /// + /// + /// True if the Address property contains a valid IPv6 address, false if it's empty or an IPv4 address + /// public bool IsIpv6 => !string.IsNullOrEmpty(Address) && ParseNetworkEndpoint(Address, Port, true).Family == NetworkFamily.Ipv6; } diff --git a/pvpExceptions.json b/pvpExceptions.json index 26975b166c..a7a2ec1d0e 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -12,42 +12,25 @@ }, "PVP-151-1": { "errors": [ - "Unity.Netcode.NetworkConfig: Prefabs: undocumented", + "Unity.Netcode.NetworkConfig: Prefabs: undocumented", + "Unity.Netcode.ConnectionEventData: EventType: undocumented", + "Unity.Netcode.RpcException: undocumented", "Unity.Netcode.RpcException: .ctor(string): undocumented", + "Unity.Netcode.NetworkManager: void NetworkUpdate(NetworkUpdateStage): undocumented", "Unity.Netcode.NetworkManager.ReanticipateDelegate: undocumented", + "Unity.Netcode.NetworkObject: NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort): undocumented", "Unity.Netcode.NetworkObject.VisibilityDelegate: missing ", "Unity.Netcode.NetworkObject.SpawnDelegate: missing ", - "Unity.Netcode.CustomMessagingManager.HandleNamedMessageDelegate: missing ", - "Unity.Netcode.CustomMessagingManager.HandleNamedMessageDelegate: missing ", + "Unity.Netcode.GenerateSerializationForGenericParameterAttribute: .ctor(int): undocumented", + "Unity.Netcode.GenerateSerializationForTypeAttribute: .ctor(Type): undocumented", - "Unity.Netcode.RpcAttribute: RequireOwnership: undocumented", - "Unity.Netcode.RpcAttribute: DeferLocal: undocumented", - "Unity.Netcode.RpcAttribute: AllowTargetOverride: undocumented", - "Unity.Netcode.RpcAttribute: .ctor(SendTo): undocumented", - "Unity.Netcode.RpcAttribute.RpcAttributeParams: undocumented", - "Unity.Netcode.RpcAttribute.RpcAttributeParams: Delivery: undocumented", - "Unity.Netcode.RpcAttribute.RpcAttributeParams: RequireOwnership: undocumented", - "Unity.Netcode.RpcAttribute.RpcAttributeParams: DeferLocal: undocumented", - "Unity.Netcode.RpcAttribute.RpcAttributeParams: AllowTargetOverride: undocumented", - "Unity.Netcode.ServerRpcAttribute: RequireOwnership: undocumented", - "Unity.Netcode.ServerRpcAttribute: .ctor(): undocumented", - "Unity.Netcode.ClientRpcAttribute: .ctor(): undocumented", - "Unity.Netcode.StaleDataHandling: undocumented", - "Unity.Netcode.StaleDataHandling: Ignore: undocumented", - "Unity.Netcode.StaleDataHandling: Reanticipate: undocumented", + "Unity.Netcode.NetworkList: void Finalize(): undocumented", - "Unity.Netcode.NetworkVariableUpdateTraits: undocumented", - "Unity.Netcode.NetworkVariableUpdateTraits: MinSecondsBetweenUpdates: undocumented", - "Unity.Netcode.NetworkVariableUpdateTraits: MaxSecondsBetweenUpdates: undocumented", - "Unity.Netcode.NetworkVariableBase: NetworkBehaviour GetBehaviour(): undocumented", - "Unity.Netcode.NetworkVariableBase: void MarkNetworkBehaviourDirty(): undocumented", - "Unity.Netcode.NetworkSceneManager: void SetClientSynchronizationMode(LoadSceneMode): XML is not well-formed: Expected an end tag for element 'summary'", - "Unity.Netcode.Transports.UTP.UnityTransport.ConnectionAddressData: IsIpv6: undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: void OnNetworkSpawn(): undocumented", From 6e84ac0e4189b4ff85db9628b4cb3ba4ecd5e8d7 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 14:00:37 +0200 Subject: [PATCH 12/16] corrected all 151-1 PVP APIs marked --- .../Connection/NetworkConnectionManager.cs | 5 ++++- .../Runtime/Core/NetworkBehaviour.cs | 7 +++++++ .../Runtime/Core/NetworkManager.cs | 8 ++++++++ .../Runtime/Core/NetworkObject.cs | 7 +++++++ ...rializationForGenericParameterAttribute.cs | 4 ++++ .../GenerateSerializationForTypeAttribute.cs | 4 ++++ .../Collections/NetworkList.cs | 3 +++ pvpExceptions.json | 20 ------------------- 8 files changed, 37 insertions(+), 21 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs b/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs index fb56d762e5..97486a8ba7 100644 --- a/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs @@ -11,7 +11,7 @@ namespace Unity.Netcode { /// - /// The connection event type set within to signify the type of connection event notification received. + /// The connection event type set within to signify the type of connection event notification received. /// /// /// is returned as a parameter of the event notification. @@ -60,6 +60,9 @@ public enum ConnectionEvent /// public struct ConnectionEventData { + /// + /// The type of connection event that occurred + /// public ConnectionEvent EventType; /// diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs index ba8e981795..98efb94b25 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs @@ -6,8 +6,15 @@ namespace Unity.Netcode { + /// + /// Exception thrown when an RPC (Remote Procedure Call) encounters an error during execution + /// public class RpcException : Exception { + /// + /// Initializes a new instance of the RpcException class with a specified error message + /// + /// The message that describes the error public RpcException(string message) : base(message) { diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs index 0aec58612f..5092390599 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs @@ -44,6 +44,10 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem #pragma warning restore IDE1006 // restore naming rule violation check + /// + /// Processes network-related updates for a specific update stage in the frame + /// + /// The current network update stage being processed public void NetworkUpdate(NetworkUpdateStage updateStage) { switch (updateStage) @@ -294,6 +298,10 @@ public event Action OnTransportFailure remove => ConnectionManager.OnTransportFailure -= value; } + /// + /// Delegate for handling network state reanticipation events + /// + /// The most recent round-trip time measurement in seconds between client and server public delegate void ReanticipateDelegate(double lastRoundTripTime); /// diff --git a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs index 3c5551cd4b..0122b696bc 100644 --- a/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs +++ b/com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs @@ -385,6 +385,7 @@ private GlobalObjectId GetGlobalId() /// Delegate type for checking visibility /// /// The clientId to check visibility for + /// True if the object should be visible to the specified client, false otherwise public delegate bool VisibilityDelegate(ulong clientId); /// @@ -396,6 +397,7 @@ private GlobalObjectId GetGlobalId() /// Delegate type for checking spawn options /// /// The clientId to check spawn options for + /// True if the object should be spawned for the specified client, false otherwise public delegate bool SpawnDelegate(ulong clientId); /// @@ -1556,6 +1558,11 @@ internal ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance) return 0; } + /// + /// Gets a NetworkBehaviour component at the specified index in this object's NetworkBehaviour list + /// + /// The zero-based index of the NetworkBehaviour to retrieve + /// The NetworkBehaviour at the specified index, or null if the index is out of bounds public NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index) { if (index >= ChildNetworkBehaviours.Count) diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForGenericParameterAttribute.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForGenericParameterAttribute.cs index a102f3666e..c8d4cedf45 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForGenericParameterAttribute.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForGenericParameterAttribute.cs @@ -74,6 +74,10 @@ public class GenerateSerializationForGenericParameterAttribute : Attribute { internal int ParameterIndex; + /// + /// Initializes a new instance of the attribute + /// + /// The zero-based index of the generic parameter that should be serialized public GenerateSerializationForGenericParameterAttribute(int parameterIndex) { ParameterIndex = parameterIndex; diff --git a/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForTypeAttribute.cs b/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForTypeAttribute.cs index 81e55c00df..5bfff33864 100644 --- a/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForTypeAttribute.cs +++ b/com.unity.netcode.gameobjects/Runtime/Messaging/GenerateSerializationForTypeAttribute.cs @@ -18,6 +18,10 @@ public class GenerateSerializationForTypeAttribute : Attribute { internal Type Type; + /// + /// Initializes a new instance of the attribute + /// + /// The type that should have serialization code generated for it public GenerateSerializationForTypeAttribute(Type type) { Type = type; diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs index eaf06bbb67..2d00a4cf97 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs @@ -49,6 +49,9 @@ public NetworkList(IEnumerable values = default, } } + /// + /// Finalizer that ensures proper cleanup of network list resources + /// ~NetworkList() { Dispose(); diff --git a/pvpExceptions.json b/pvpExceptions.json index a7a2ec1d0e..bfca45c47a 100644 --- a/pvpExceptions.json +++ b/pvpExceptions.json @@ -12,26 +12,6 @@ }, "PVP-151-1": { "errors": [ - "Unity.Netcode.NetworkConfig: Prefabs: undocumented", - - "Unity.Netcode.ConnectionEventData: EventType: undocumented", - - "Unity.Netcode.RpcException: undocumented", - "Unity.Netcode.RpcException: .ctor(string): undocumented", - - "Unity.Netcode.NetworkManager: void NetworkUpdate(NetworkUpdateStage): undocumented", - "Unity.Netcode.NetworkManager.ReanticipateDelegate: undocumented", - - "Unity.Netcode.NetworkObject: NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort): undocumented", - "Unity.Netcode.NetworkObject.VisibilityDelegate: missing ", - "Unity.Netcode.NetworkObject.SpawnDelegate: missing ", - - "Unity.Netcode.GenerateSerializationForGenericParameterAttribute: .ctor(int): undocumented", - - "Unity.Netcode.GenerateSerializationForTypeAttribute: .ctor(Type): undocumented", - - "Unity.Netcode.NetworkList: void Finalize(): undocumented", - "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: void OnNetworkSpawn(): undocumented", "Unity.Netcode.TestHelpers.Runtime.ObjectNameIdentifier: void RegisterAndLabelNetworkObject(): undocumented", From 2f2cadaa392e069ff2f08c033085d7067ef9f7f0 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 14:37:40 +0200 Subject: [PATCH 13/16] Few new corrections --- .../Runtime/Configuration/NetworkPrefab.cs | 4 ++-- .../TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs | 3 +-- .../Tests/Runtime/Components/BufferDataValidationComponent.cs | 1 + .../Runtime/NetworkVariableBaseInitializesWhenPersisted.cs | 2 ++ 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs index c101104269..c6f30d2835 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkPrefab.cs @@ -74,7 +74,7 @@ public bool Equals(NetworkPrefab other) /// /// Gets the GlobalObjectIdHash of the source prefab based on the current override settings /// - /// The hash value identifying the source prefab + /// The hash value identifying the source prefab /// Thrown when required prefab references are missing or invalid /// Thrown when Override has an invalid value public uint SourcePrefabGlobalObjectIdHash @@ -112,7 +112,7 @@ public uint SourcePrefabGlobalObjectIdHash /// /// Gets the GlobalObjectIdHash of the target prefab when using prefab overrides /// - /// The hash value identifying the target prefab, or 0 if no override is set + /// The hash value identifying the target prefab, or 0 if no override is set /// Thrown when required prefab references are missing or invalid /// Thrown when Override has an invalid value public uint TargetPrefabGlobalObjectIdHash diff --git a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs index d09736a387..8e55718b90 100644 --- a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs +++ b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs @@ -615,10 +615,9 @@ public static IEnumerator WaitForClientConnected(NetworkManager client, ResultWr /// /// Similar to WaitForClientConnected, this waits for multiple clients to be connected. /// - /// The clients to be connected + /// Array of clients to wait for /// The result. If null, it will automatically assert< /// Maximum time in seconds to wait for the object to be found. - /// public static IEnumerator WaitForClientsConnected(NetworkManager[] clients, ResultWrapper result = null, float timeout = DefaultTimeout) { // Make sure none are the host client diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs b/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs index 0e2b7fd869..8647f586d2 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/Components/BufferDataValidationComponent.cs @@ -54,6 +54,7 @@ private void Start() /// /// Returns back whether the test has completed the total number of iterations /// + /// True if the test has exceeded maximum buffer size or failed, false otherwise public bool IsTestComplete() { if (m_CurrentBufferSize > MaximumBufferSize || TestFailed) diff --git a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs index 2ce7186db6..6996cb70f4 100644 --- a/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs +++ b/com.unity.netcode.gameobjects/Tests/Runtime/NetworkVariableBaseInitializesWhenPersisted.cs @@ -335,6 +335,8 @@ public void Initialize(NetworkManager networkManager) /// This validates that the instances persisted to the next test set and persisted /// between network sessions /// + /// The minimum number of times each instance should have been spawned + /// True if all instances meet the minimum spawn count requirement, false otherwise public bool ValidateInstanceSpawnCount(int minCount) { // First pass we should have no instances From fae73a58f0d92ef8a4c57766872a521234df142b Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 14:46:18 +0200 Subject: [PATCH 14/16] more corrections --- .../Runtime/NetworkVariable/AnticipatedNetworkVariable.cs | 8 ++++++++ .../Runtime/NetworkVariable/NetworkVariable.cs | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs index fce8c058f0..9100259a23 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/AnticipatedNetworkVariable.cs @@ -259,6 +259,11 @@ public T AuthoritativeValue private SmoothDelegate m_SmoothDelegate = null; + /// + /// Initializes a new instance of the AnticipatedNetworkVariable class + /// + /// The initial value for the network variable. Defaults to the type's default value if not specified. + /// Determines how the variable handles authoritative updates that are older than the current anticipated state. Defaults to StaleDataHandling.Ignore. public AnticipatedNetworkVariable(T value = default, StaleDataHandling staleDataHandling = StaleDataHandling.Ignore) : base() @@ -334,6 +339,9 @@ public override void Dispose() } } + /// + /// Finalizer that ensures proper cleanup of network variable resources + /// ~AnticipatedNetworkVariable() { Dispose(); diff --git a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs index b70084588e..bd629f0155 100644 --- a/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs +++ b/com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariable.cs @@ -106,7 +106,7 @@ public void Reset(T value = default) // The introduction of standard .NET collections caused an issue with permissions since there is no way to detect changes in the // collection without doing a full comparison. While this approach does consume more memory per collection instance, it is the // lowest risk approach to resolving the issue where a client with no write permissions could make changes to a collection locally - // which can cause a myriad of issues. + // which can cause a myriad of issues. private protected T m_InternalOriginalValue; private protected T m_PreviousValue; @@ -151,11 +151,12 @@ public virtual T Value /// Invoke this method to check if a collection's items are dirty. /// The default behavior is to exit early if the is already dirty. /// + /// when true, this check will force a full item collection check even if the NetworkVariable is already dirty + /// True if the variable is dirty and needs synchronization, false if clean or client lacks write permissions /// /// This is to be used as a way to check if a containing a managed collection has any changees to the collection items.
/// If you invoked this when a collection is dirty, it will not trigger the unless you set forceCheck param to true.
///
- /// when true, this check will force a full item collection check even if the NetworkVariable is already dirty public bool CheckDirtyState(bool forceCheck = false) { var isDirty = base.IsDirty(); @@ -333,7 +334,7 @@ public override void ReadDelta(FastBufferReader reader, bool keepDirtyDelta) /// This should be always invoked (client & server) to assure the previous values are set /// !! IMPORTANT !! /// When a server forwards delta updates to connected clients, it needs to preserve the previous dirty value(s) - /// until it is done serializing all valid NetworkVariable field deltas (relative to each client). This is invoked + /// until it is done serializing all valid NetworkVariable field deltas (relative to each client). This is invoked /// after it is done forwarding the deltas at the end of the method. /// internal override void PostDeltaRead() From 412edb7b2f96672f7f16b67535bca81e7ae1abfb Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 14:52:30 +0200 Subject: [PATCH 15/16] corrections --- .../Runtime/Configuration/NetworkConfig.cs | 3 +++ .../TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs index 7c3cb964af..85f9acd311 100644 --- a/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs +++ b/com.unity.netcode.gameobjects/Runtime/Configuration/NetworkConfig.cs @@ -31,6 +31,9 @@ public class NetworkConfig [Tooltip("When set, NetworkManager will automatically create and spawn the assigned player prefab. This can be overridden by adding it to the NetworkPrefabs list and selecting override.")] public GameObject PlayerPrefab; + /// + /// The collection of network prefabs available for spawning across the network + /// [SerializeField] public NetworkPrefabs Prefabs = new NetworkPrefabs(); diff --git a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs index 8e55718b90..15081cae6f 100644 --- a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs +++ b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs @@ -425,6 +425,7 @@ private static void SceneManagerValidationAndTestRunnerInitialization(NetworkMan /// The Server NetworkManager /// The Clients NetworkManager /// called immediately after server is started and before client(s) are started + /// True if the network instances were started successfully, throws InvalidOperationException if already started public static bool Start(bool host, NetworkManager server, NetworkManager[] clients, BeforeClientStartCallback callback = null) { if (s_IsStarted) @@ -616,7 +617,7 @@ public static IEnumerator WaitForClientConnected(NetworkManager client, ResultWr /// Similar to WaitForClientConnected, this waits for multiple clients to be connected. /// /// Array of clients to wait for - /// The result. If null, it will automatically assert< + /// The result. If null, it will automatically assert /// Maximum time in seconds to wait for the object to be found. public static IEnumerator WaitForClientsConnected(NetworkManager[] clients, ResultWrapper result = null, float timeout = DefaultTimeout) { From 281f06da191d33ddd29e2b86e4b19e4c3eeda052 Mon Sep 17 00:00:00 2001 From: michalChrobot Date: Tue, 8 Apr 2025 14:56:15 +0200 Subject: [PATCH 16/16] correction --- .../TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs index 15081cae6f..89319a0d3d 100644 --- a/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs +++ b/com.unity.netcode.gameobjects/TestHelpers/Runtime/NetcodeIntegrationTestHelpers.cs @@ -619,6 +619,7 @@ public static IEnumerator WaitForClientConnected(NetworkManager client, ResultWr /// Array of clients to wait for /// The result. If null, it will automatically assert /// Maximum time in seconds to wait for the object to be found. + /// An IEnumerator that yields until all clients are connected or timeout is reached public static IEnumerator WaitForClientsConnected(NetworkManager[] clients, ResultWrapper result = null, float timeout = DefaultTimeout) { // Make sure none are the host client