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

Merged
merged 32 commits into from
Jun 24, 2025
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 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
0f2f876
Merge branch 'develop' into pvp-fixes-develop-v2
michalChrobot Jun 17, 2025
83ca2e2
Merge branch 'develop' into pvp-fixes-develop-v2
michalChrobot Jun 23, 2025
bf31b17
Update NetworkList.cs
NoelStephensUnity Jun 23, 2025
d52e5a7
Update NetworkVariableBase.cs
NoelStephensUnity Jun 23, 2025
dfd57a3
Update NetworkTransport.cs
NoelStephensUnity Jun 23, 2025
994aa55
Update UnityTransport.cs
NoelStephensUnity Jun 23, 2025
8d95b4e
Update NetcodeIntegrationTestHelpers.cs
NoelStephensUnity Jun 23, 2025
5d6004f
Update BufferDataValidationComponent.cs
NoelStephensUnity Jun 23, 2025
f6f94d1
Update NetworkVariableBaseInitializesWhenPersisted.cs
NoelStephensUnity Jun 23, 2025
8b4e1cd
style
NoelStephensUnity Jun 23, 2025
653d42c
style
NoelStephensUnity Jun 23, 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 @@ -34,11 +34,14 @@ public class NetworkPrefabs
/// This is used for the legacy way of spawning NetworkPrefabs with an override when manually instantiating and spawning.
/// To handle multiple source NetworkPrefab overrides that all point to the same target NetworkPrefab use
/// <see cref="NetworkSpawnManager.InstantiateAndSpawn(NetworkObject, ulong, bool, bool, bool, Vector3, Quaternion)"/>
/// or <see cref="NetworkObject.InstantiateAndSpawn(NetworkManager, ulong, bool, bool, bool, Vector3, Quaternion)"/>
/// or <see cref="NetworkObject.InstantiateAndSpawn(NetworkManager, ulong, bool, bool, bool, Vector3, Quaternion)"/>.
/// </summary>
[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,14 +65,16 @@ private void RemoveTriggeredByNetworkPrefabList(NetworkPrefab networkPrefab)
m_Prefabs.Remove(networkPrefab);
}

/// <summary>
/// Destructor that cleans up network prefab resources.
/// </summary>
~NetworkPrefabs()
{
Shutdown();
}

/// <summary>
/// Deregister from add and remove events
/// Clear the list
/// Deregister from add and remove events and clear the events.
/// </summary>
internal void Shutdown()
{
Expand All @@ -84,6 +89,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 @@ -154,11 +160,12 @@ public void Initialize(bool warnInvalid = true)
}

/// <summary>
/// Add a new NetworkPrefab instance to the list
/// Add a new NetworkPrefab instance to the list.
/// </summary>
/// <param name="networkPrefab">The <see cref="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.
///
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.<br />
/// Any modifications made here are not persisted. Permanent configuration changes should be done
/// through the <see cref="NetworkPrefabsList"/> scriptable object property.
/// </remarks>
Expand All @@ -175,11 +182,11 @@ public bool Add(NetworkPrefab networkPrefab)
}

/// <summary>
/// Remove a NetworkPrefab instance from the list
/// Remove a NetworkPrefab instance from the list.
/// </summary>
/// <param name="prefab">The <see cref="NetworkPrefab"/> to remove.</param>
/// <remarks>
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
///
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.<br />
/// Any modifications made here are not persisted. Permanent configuration changes should be done
/// through the <see cref="NetworkPrefabsList"/> scriptable object property.
/// </remarks>
Expand All @@ -197,11 +204,11 @@ public void Remove(NetworkPrefab prefab)
}

/// <summary>
/// Remove a NetworkPrefab instance with matching <see cref="NetworkPrefab.Prefab"/> from the list
/// Remove a NetworkPrefab instance with matching <see cref="NetworkPrefab.Prefab"/> from the list.
/// </summary>
/// <param name="prefab">The <see cref="GameObject"/> to match against for removal.</param>
/// <remarks>
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.
///
/// The framework does not synchronize this list between clients. Any runtime changes must be handled manually.<br />
/// Any modifications made here are not persisted. Permanent configuration changes should be done
/// through the <see cref="NetworkPrefabsList"/> scriptable object property.
/// </remarks>
Expand Down Expand Up @@ -232,10 +239,10 @@ public void Remove(GameObject prefab)
}

/// <summary>
/// Check if the given GameObject is present as a prefab within the list
/// Check if the given GameObject is present as a prefab within the list.
/// </summary>
/// <param name="prefab">The prefab to check</param>
/// <returns>Whether or not the prefab exists</returns>
/// <param name="prefab">The prefab to check.</param>
/// <returns>True if the prefab exists or false if it does not.</returns>
public bool Contains(GameObject prefab)
{
for (int i = 0; i < m_Prefabs.Count; i++)
Expand All @@ -251,10 +258,10 @@ public bool Contains(GameObject prefab)
}

/// <summary>
/// Check if the given NetworkPrefab is present within the list
/// Check if the given NetworkPrefab is present within the list.
/// </summary>
/// <param name="prefab">The prefab to check</param>
/// <returns>Whether or not the prefab exists</returns>
/// <param name="prefab">The prefab to check.</param>
/// <returns>True if the prefab exists or false if it does not.</returns>
public bool Contains(NetworkPrefab prefab)
{
for (int i = 0; i < m_Prefabs.Count; i++)
Expand All @@ -269,7 +276,7 @@ public bool Contains(NetworkPrefab prefab)
}

/// <summary>
/// Configures <see cref="NetworkPrefabOverrideLinks"/> for the given <see cref="NetworkPrefab"/>
/// Configures <see cref="NetworkPrefabOverrideLinks"/> for the given <see cref="NetworkPrefab"/>.
/// </summary>
private bool AddPrefabRegistration(NetworkPrefab networkPrefab)
{
Expand Down
Loading