Skip to content

docs: [1.X] fixes of PVP exceptions (round 2) #3374

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7a95a10
Initial PR to separate Test stuff from Missing API description
michalChrobot Apr 1, 2025
96cb8d8
150-1 PVP fixes
michalChrobot Apr 8, 2025
cee23f1
Merge branch 'develop' into pvp-fixes-develop-v2
michalChrobot Apr 8, 2025
6d9bf0d
NetworkPrefab and NetworkPrefabs corrections
michalChrobot Apr 7, 2025
0fedf0c
The rest of NetworkPrefab APIs
michalChrobot Apr 8, 2025
6f14dd8
Merge branch 'pvp-fixes-develop-v2' of https://github.com/Unity-Techn…
michalChrobot Apr 8, 2025
40c6e58
AnticipatedNetworkVariable corrected
michalChrobot Apr 7, 2025
0917354
pvpException file corrections after AnticipatedNetworkVariable changes
michalChrobot Apr 8, 2025
cdc7560
NetworkVariable corrections and added inheritdocs when API is override
michalChrobot Apr 8, 2025
4aa8320
pvpExceptions update after cherry pick
michalChrobot Apr 8, 2025
35dad81
RpcParams corrections
michalChrobot Apr 7, 2025
86f224c
NetworkTransport corrections
michalChrobot Apr 8, 2025
ec8041d
Bunch of API additions
michalChrobot Apr 8, 2025
6e84ac0
corrected all 151-1 PVP APIs marked
michalChrobot Apr 8, 2025
2f2cada
Few new corrections
michalChrobot Apr 8, 2025
fae73a5
more corrections
michalChrobot Apr 8, 2025
412edb7
corrections
michalChrobot Apr 8, 2025
281f06d
correction
michalChrobot Apr 8, 2025
7d1c3eb
Merge branch 'develop' into pvp-fixes-develop-v2
michalChrobot Apr 11, 2025
ded6aaa
Merge branch 'develop' into pvp-fixes-develop-v2
michalChrobot Apr 11, 2025
2cf2019
Merge branch 'develop' into pvp-fixes-develop-v2
EmandM Apr 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/// <summary>
/// The collection of network prefabs available for spawning across the network
/// </summary>
[SerializeField]
public NetworkPrefabs Prefabs = new NetworkPrefabs();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ public class NetworkPrefab
/// </summary>
public GameObject OverridingTargetPrefab;

/// <summary>
/// Compares this NetworkPrefab with another to determine equality
/// </summary>
/// <param name="other">The NetworkPrefab to compare against</param>
/// <returns>True if all fields match between the two NetworkPrefabs, false otherwise</returns>
public bool Equals(NetworkPrefab other)
{
return Override == other.Override &&
Expand All @@ -66,6 +71,12 @@ public bool Equals(NetworkPrefab other)
OverridingTargetPrefab == other.OverridingTargetPrefab;
}

/// <summary>
/// Gets the GlobalObjectIdHash of the source prefab based on the current override settings
/// </summary>
/// <value>The hash value identifying the source prefab</value>
/// <exception cref="InvalidOperationException">Thrown when required prefab references are missing or invalid</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when Override has an invalid value</exception>
public uint SourcePrefabGlobalObjectIdHash
{
get
Expand Down Expand Up @@ -98,6 +109,12 @@ public uint SourcePrefabGlobalObjectIdHash
}
}

/// <summary>
/// Gets the GlobalObjectIdHash of the target prefab when using prefab overrides
/// </summary>
/// <value>The hash value identifying the target prefab, or 0 if no override is set</value>
/// <exception cref="InvalidOperationException">Thrown when required prefab references are missing or invalid</exception>
/// <exception cref="ArgumentOutOfRangeException">Thrown when Override has an invalid value</exception>
public uint TargetPrefabGlobalObjectIdHash
{
get
Expand All @@ -122,6 +139,11 @@ public uint TargetPrefabGlobalObjectIdHash
}
}

/// <summary>
/// Validates the NetworkPrefab configuration to ensure all required fields are properly set
/// </summary>
/// <param name="index">Optional index used for error reporting when validating lists of prefabs</param>
/// <returns>True if the NetworkPrefab is valid and ready for use, false otherwise</returns>
public bool Validate(int index = -1)
{
NetworkObject networkObject;
Expand Down Expand Up @@ -224,6 +246,10 @@ public bool Validate(int index = -1)
return true;
}

/// <summary>
/// Returns a string representation of this NetworkPrefab's source and target hash values
/// </summary>
/// <returns>A string containing the source and target hash values</returns>
public override string ToString()
{
return $"{{SourceHash: {SourceHashToOverride}, TargetHash: {TargetPrefabGlobalObjectIdHash}}}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ public class NetworkPrefabs
[NonSerialized]
public Dictionary<uint, uint> OverrideToNetworkPrefab = new Dictionary<uint, uint>();

/// <summary>
/// Gets the read-only list of all registered network prefabs
/// </summary>
public IReadOnlyList<NetworkPrefab> Prefabs => m_Prefabs;

[NonSerialized]
Expand All @@ -62,6 +65,9 @@ private void RemoveTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab)
m_Prefabs.Remove(networkPrefab);
}

/// <summary>
/// Finalizer that ensures proper cleanup of network prefab resources
/// </summary>
~NetworkPrefabs()
{
Shutdown();
Expand All @@ -84,6 +90,7 @@ internal void Shutdown()
/// Processes the <see cref="NetworkPrefabsList"/> if one is present for use during runtime execution,
/// else processes <see cref="Prefabs"/>.
/// </summary>
/// <param name="warnInvalid">When true, logs warnings about invalid prefabs that are removed during initialization</param>
public void Initialize(bool warnInvalid = true)
{
m_Prefabs.Clear();
Expand Down Expand Up @@ -156,6 +163,8 @@ public void Initialize(bool warnInvalid = true)
/// <summary>
/// Add a new NetworkPrefab instance to the list
/// </summary>
/// <param name="networkPrefab">The NetworkPrefab to add</param>
/// <returns>True if the prefab was successfully added, false if it was invalid or already registered</returns>
/// <remarks>
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
///
Expand All @@ -177,6 +186,7 @@ public bool Add(NetworkPrefab networkPrefab)
/// <summary>
/// Remove a NetworkPrefab instance from the list
/// </summary>
/// <param name="prefab">The NetworkPrefab to remove</param>
/// <remarks>
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
///
Expand All @@ -199,6 +209,7 @@ public void Remove(NetworkPrefab prefab)
/// <summary>
/// Remove a NetworkPrefab instance with matching <see cref="NetworkPrefab.Prefab"/> from the list
/// </summary>
/// <param name="prefab">The GameObject to match against for removal</param>
/// <remarks>
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
namespace Unity.Netcode
{
/// <summary>
/// The connection event type set within <see cref="ConnectionEventData"/> to signify the type of connection event notification received.
/// The connection event type set within <see cref="ConnectionEventData"/> to signify the type of connection event notification received.
/// </summary>
/// <remarks>
/// <see cref="ConnectionEventData"/> is returned as a parameter of the <see cref="NetworkManager.OnConnectionEvent"/> event notification.
Expand Down Expand Up @@ -60,6 +60,9 @@ public enum ConnectionEvent
/// </remarks>
public struct ConnectionEventData
{
/// <summary>
/// The type of connection event that occurred
/// </summary>
public ConnectionEvent EventType;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@

namespace Unity.Netcode
{
/// <summary>
/// Exception thrown when an RPC (Remote Procedure Call) encounters an error during execution
/// </summary>
public class RpcException : Exception
{
/// <summary>
/// Initializes a new instance of the RpcException class with a specified error message
/// </summary>
/// <param name="message">The message that describes the error</param>
public RpcException(string message) : base(message)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class NetworkManager : MonoBehaviour, INetworkUpdateSystem

#pragma warning restore IDE1006 // restore naming rule violation check

/// <summary>
/// Processes network-related updates for a specific update stage in the frame
/// </summary>
/// <param name="updateStage">The current network update stage being processed</param>
public void NetworkUpdate(NetworkUpdateStage updateStage)
{
switch (updateStage)
Expand Down Expand Up @@ -294,6 +298,10 @@ public event Action OnTransportFailure
remove => ConnectionManager.OnTransportFailure -= value;
}

/// <summary>
/// Delegate for handling network state reanticipation events
/// </summary>
/// <param name="lastRoundTripTime">The most recent round-trip time measurement in seconds between client and server</param>
public delegate void ReanticipateDelegate(double lastRoundTripTime);

/// <summary>
Expand Down
7 changes: 7 additions & 0 deletions com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ private GlobalObjectId GetGlobalId()
/// Delegate type for checking visibility
/// </summary>
/// <param name="clientId">The clientId to check visibility for</param>
/// <returns>True if the object should be visible to the specified client, false otherwise</returns>
public delegate bool VisibilityDelegate(ulong clientId);

/// <summary>
Expand All @@ -399,6 +400,7 @@ private GlobalObjectId GetGlobalId()
/// Delegate type for checking spawn options
/// </summary>
/// <param name="clientId">The clientId to check spawn options for</param>
/// <returns>True if the object should be spawned for the specified client, false otherwise</returns>
public delegate bool SpawnDelegate(ulong clientId);

/// <summary>
Expand Down Expand Up @@ -1565,6 +1567,11 @@ internal ushort GetNetworkBehaviourOrderIndex(NetworkBehaviour instance)
return 0;
}

/// <summary>
/// Gets a NetworkBehaviour component at the specified index in this object's NetworkBehaviour list
/// </summary>
/// <param name="index">The zero-based index of the NetworkBehaviour to retrieve</param>
/// <returns>The NetworkBehaviour at the specified index, or null if the index is out of bounds</returns>
public NetworkBehaviour GetNetworkBehaviourAtOrderIndex(ushort index)
{
if (index >= ChildNetworkBehaviours.Count)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public void SendUnnamedMessage(ulong clientId, FastBufferWriter messageBuffer, N
/// <summary>
/// Delegate used to handle named messages
/// </summary>
/// <param name="senderClientId">The client identifier of the message sender</param>
/// <param name="messagePayload">The buffer containing the message data to be read</param>
public delegate void HandleNamedMessageDelegate(ulong senderClientId, FastBufferReader messagePayload);

private Dictionary<ulong, HandleNamedMessageDelegate> m_NamedMessageHandlers32 = new Dictionary<ulong, HandleNamedMessageDelegate>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ public class GenerateSerializationForGenericParameterAttribute : Attribute
{
internal int ParameterIndex;

/// <summary>
/// Initializes a new instance of the attribute
/// </summary>
/// <param name="parameterIndex">The zero-based index of the generic parameter that should be serialized</param>
public GenerateSerializationForGenericParameterAttribute(int parameterIndex)
{
ParameterIndex = parameterIndex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public class GenerateSerializationForTypeAttribute : Attribute
{
internal Type Type;

/// <summary>
/// Initializes a new instance of the attribute
/// </summary>
/// <param name="type">The type that should have serialization code generated for it</param>
public GenerateSerializationForTypeAttribute(Type type)
{
Type = type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,29 @@ public enum RpcDelivery
public class RpcAttribute : Attribute
{
// Must match the set of parameters below
/// <summary>
/// Parameters that define the behavior of an RPC
/// </summary>
public struct RpcAttributeParams
{
/// <summary>
/// The delivery method for the RPC
/// </summary>
public RpcDelivery Delivery;

/// <summary>
/// When true, only the owner of the object can execute this RPC
/// </summary>
public bool RequireOwnership;

/// <summary>
/// When true, local execution of the RPC is deferred until the next network tick
/// </summary>
public bool DeferLocal;

/// <summary>
/// When true, allows the RPC target to be overridden at runtime
/// </summary>
public bool AllowTargetOverride;
}

Expand All @@ -38,10 +56,26 @@ public struct RpcAttributeParams
/// Type of RPC delivery method
/// </summary>
public RpcDelivery Delivery = RpcDelivery.Reliable;

/// <summary>
/// When true, only the owner of the object can execute this RPC
/// </summary>
public bool RequireOwnership;

/// <summary>
/// When true, local execution of the RPC is deferred until the next network tick
/// </summary>
public bool DeferLocal;

/// <summary>
/// When true, allows the RPC target to be overridden at runtime
/// </summary>
public bool AllowTargetOverride;

/// <summary>
/// Initializes a new instance of the RpcAttribute with the specified target
/// </summary>
/// <param name="target">The target for this RPC</param>
public RpcAttribute(SendTo target)
{
}
Expand All @@ -60,8 +94,14 @@ private RpcAttribute()
[AttributeUsage(AttributeTargets.Method)]
public class ServerRpcAttribute : RpcAttribute
{
/// <summary>
/// When true, only the owner of the NetworkObject can invoke this ServerRpc
/// </summary>
public new bool RequireOwnership;

/// <summary>
/// Initializes a new instance of ServerRpcAttribute configured to target the server
/// </summary>
public ServerRpcAttribute() : base(SendTo.Server)
{

Expand All @@ -75,6 +115,9 @@ public ServerRpcAttribute() : base(SendTo.Server)
[AttributeUsage(AttributeTargets.Method)]
public class ClientRpcAttribute : RpcAttribute
{
/// <summary>
/// Initializes a new instance of ClientRpcAttribute configured to target all non-server clients
/// </summary>
public ClientRpcAttribute() : base(SendTo.NotServer)
{

Expand Down
Loading