Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

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

Merged
merged 20 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
c0bf5af
@michalChrobot Initial PR to separate Test stuff from Missing API des…
michalChrobot Apr 1, 2025
f020234
Merge branch 'develop-2.0.0' into pvp-fixes-develop-2.0.0-round2
michalChrobot Apr 7, 2025
abb16b0
NetworkClient corrections
michalChrobot Apr 7, 2025
b79641a
NetworkBehaviour corrections
michalChrobot Apr 7, 2025
806a3a8
NetworkObject corrections
michalChrobot Apr 7, 2025
48e407b
RpcParams corrections
michalChrobot Apr 7, 2025
94f662c
RpcAttributes corrections
michalChrobot Apr 7, 2025
69590ad
AnticipatedNetworkVariable corrected
michalChrobot Apr 7, 2025
6843336
NetworkPrefab and NetworkPrefabs corrections
michalChrobot Apr 7, 2025
2793ec8
NetworkConfig corrections
michalChrobot Apr 7, 2025
9b6be08
AnticipatedNetworkTransform corrections
michalChrobot Apr 8, 2025
802e183
NetworkVariable corrections and added inheritdocs when API is override
michalChrobot Apr 8, 2025
27e7677
NetworkTransport corrections
michalChrobot Apr 8, 2025
2d3c0a5
Corrected all other 151-1 exempted APIs beside the test related ones
michalChrobot Apr 8, 2025
97bd8e0
Merge branch 'develop-2.0.0' into pvp-fixes-develop-2.0.0-round2
michalChrobot Apr 8, 2025
4de5946
corrected additional APIs
michalChrobot Apr 8, 2025
8243284
more corrections
michalChrobot Apr 8, 2025
0e9d591
Merge branch 'develop-2.0.0' into pvp-fixes-develop-2.0.0-round2
michalChrobot Apr 11, 2025
7393831
Merge branch 'develop-2.0.0' into pvp-fixes-develop-2.0.0-round2
michalChrobot Apr 11, 2025
ed14603
Merge branch 'develop-2.0.0' into pvp-fixes-develop-2.0.0-round2
michalChrobot Apr 11, 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 @@ -286,6 +286,7 @@ private void ProcessSmoothing()
// TODO: This does not handle OnFixedUpdate
// This requires a complete overhaul in this class to switch between using
// NetworkRigidbody's position and rotation values.
/// <inheritdoc/>
public override void OnUpdate()
{
ProcessSmoothing();
Expand Down Expand Up @@ -422,6 +423,7 @@ protected internal override void InternalOnNetworkPostSpawn()
}
}

/// <inheritdoc/>
public override void OnNetworkSpawn()
{
if (NetworkManager.DistributedAuthorityMode)
Expand All @@ -445,6 +447,7 @@ public override void OnNetworkSpawn()
NetworkManager.AnticipationSystem.AllAnticipatedObjects.Add(m_AnticipatedObject);
}

/// <inheritdoc/>
public override void OnNetworkDespawn()
{
if (m_AnticipatedObject != null)
Expand All @@ -459,6 +462,7 @@ public override void OnNetworkDespawn()
base.OnNetworkDespawn();
}

/// <inheritdoc/>
public override void OnDestroy()
{
if (m_AnticipatedObject != null)
Expand Down Expand Up @@ -510,19 +514,22 @@ public void Smooth(TransformState from, TransformState to, float durationSeconds
m_CurrentSmoothTime = 0;
}

/// <inheritdoc/>
protected override void OnBeforeUpdateTransformState()
{
// this is called when new data comes from the server
m_LastAuthorityUpdateCounter = NetworkManager.AnticipationSystem.LastAnticipationAck;
m_OutstandingAuthorityChange = true;
}

/// <inheritdoc/>
protected override void OnNetworkTransformStateUpdated(ref NetworkTransformState oldState, ref NetworkTransformState newState)
{
base.OnNetworkTransformStateUpdated(ref oldState, ref newState);
ApplyAuthoritativeState();
}

/// <inheritdoc/>
protected override void OnTransformUpdated()
{
if (CanCommitToTransform || m_AnticipatedObject == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,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 that can be spawned across the network
/// </summary>
[SerializeField]
public NetworkPrefabs Prefabs = new NetworkPrefabs();

Expand Down Expand Up @@ -159,12 +162,21 @@ public class NetworkConfig
/// </summary>
public const int RttWindowSize = 64; // number of slots to use for RTT computations (max number of in-flight packets)

/// <summary>
/// Determines whether to use the client-server or distributed authority network topology
/// </summary>
[Tooltip("Determines whether to use the client-server or distributed authority network topology.")]
public NetworkTopologyTypes NetworkTopology;

/// <summary>
/// Internal flag for Cloud Multiplayer Build service integration
/// </summary>
[HideInInspector]
public bool UseCMBService;

/// <summary>
/// When enabled (default), the player prefab will automatically be spawned client-side upon the client being approved and synchronized
/// </summary>
[Tooltip("When enabled (default), the player prefab will automatically be spawned (client-side) upon the client being approved and synchronized.")]
public bool AutoSpawnPlayerPrefabClientSide = true;

Expand Down Expand Up @@ -205,7 +217,7 @@ internal NetworkConfig Copy()
return networkConfig;
}

#endif
#endif


#if MULTIPLAYER_TOOLS
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 @@ -34,8 +34,14 @@ public class NetworkClient
/// </summary>
internal bool IsApproved { get; set; }

/// <summary>
/// Defines the network topology type being used for the current network session
/// </summary>
public NetworkTopologyTypes NetworkTopologyType { get; internal set; }

/// <summary>
/// Indicates whether this client is running in Distributed Authority Host mode
/// </summary>
public bool DAHost { get; internal set; }

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
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
18 changes: 18 additions & 0 deletions 18 com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs
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 Expand Up @@ -694,6 +701,9 @@ public virtual void OnNetworkSpawn() { }
/// </remarks>
protected virtual void OnNetworkPostSpawn() { }

/// <summary>
/// Internal implementation of post-spawn functionality. Called after OnNetworkSpawn to handle internal post-spawn operations.
/// </summary>
protected internal virtual void InternalOnNetworkPostSpawn() { }

/// <summary>
Expand All @@ -708,6 +718,9 @@ protected internal virtual void InternalOnNetworkPostSpawn() { }
/// </remarks>
protected virtual void OnNetworkSessionSynchronized() { }

/// <summary>
/// Internal implementation of network session synchronization. Handles the internal processing of session synchronization events.
/// </summary>
protected internal virtual void InternalOnNetworkSessionSynchronized() { }

/// <summary>
Expand Down Expand Up @@ -1386,6 +1399,11 @@ protected virtual void OnSynchronize<T>(ref BufferSerializer<T> serializer) wher

}

/// <summary>
/// Called when network conditions require reanticipation of game state.
/// Override this method to handle adjustments needed when network latency changes.
/// </summary>
/// <param name="lastRoundTripTime">The most recent round trip time measurement in seconds</param>
public virtual void OnReanticipate(double lastRoundTripTime)
{

Expand Down
11 changes: 11 additions & 0 deletions 11 com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ internal void HandleRedistributionToClients()

internal List<NetworkObject> DeferredDespawnObjects = new List<NetworkObject>();

/// <summary>
/// Gets the client identifier of the current session owner in distributed authority mode
/// </summary>
public ulong CurrentSessionOwner { get; internal set; }

/// <summary>
Expand Down Expand Up @@ -312,6 +315,10 @@ private void UpdateTopology()
}
}

/// <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 @@ -643,6 +650,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
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.