Skip to content

Commit 1d22804

Browse files
chore: final 2.0.0 clean up tasks (#3052)
* chore Add unique message when invoking NetworkConnectionManager.DisconnectClient while in a distributed authority session. * fix Make the NetworkTransformEditor use NetworkTransform as the base type so it doesn't show a foldout group when using a non-derived component. * fix Adding ToolTips to NetworkObject (MTTB-184) * fix Just log a warning when developer logging is enabled if a client or server receives a universal RPC message for a NetworkObject that does not exist. * fix Making NetworkAnimator.Awake a protected and virtual method. * style removing using directive. * update Adding changelog entries. * style updating XML API documentation for `NetworkTransform.Teleport`
1 parent 7389f8b commit 1d22804

File tree

8 files changed

+43
-20
lines changed

8 files changed

+43
-20
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1010

1111
### Added
1212

13+
- Added tooltips for all of the `NetworkObject` component's properties. (#3052)
1314
- Added message size validation to named and unnamed message sending functions for better error messages. (#3049)
1415
- Added "Check for NetworkObject Component" property to the Multiplayer->Netcode for GameObjects project settings. When disabled, this will bypass the in-editor `NetworkObject` check on `NetworkBehaviour` components. (#3031)
1516
- Added `NetworkTransform.SwitchTransformSpaceWhenParented` property that, when enabled, will handle the world to local, local to world, and local to local transform space transitions when interpolation is enabled. (#3013)
@@ -20,6 +21,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
2021

2122
### Fixed
2223

24+
- Fixed issue where an exception could occur when receiving a universal RPC for a `NetworkObject` that has been despawned. (#3052)
2325
- Fixed issue where a NetworkObject hidden from a client that is then promoted to be session owner was not being synchronized with newly joining clients.(#3051)
2426
- Fixed issue where clients could have a wrong time delta on `NetworkVariableBase` which could prevent from sending delta state updates. (#3045)
2527
- Fixed issue where setting a prefab hash value during connection approval but not having a player prefab assigned could cause an exception when spawning a player. (#3042)
@@ -30,6 +32,9 @@ Additional documentation and release notes are available at [Multiplayer Documen
3032

3133
### Changed
3234

35+
- Changed `NetworkTransformEditor` now uses `NetworkTransform` as the base type class to assure it doesn't display a foldout group when using the base `NetworkTransform` component class. (#3052)
36+
- Changed `NetworkAnimator.Awake` is now a protected virtual method. (#3052)
37+
- Changed when invoking `NetworkManager.ConnectionManager.DisconnectClient` during a distributed authority session a more appropriate message is logged. (#3052)
3338
- Changed `NetworkTransformEditor` so it now derives from `NetcodeEditorBase`. (#3013)
3439
- Changed `NetworkRigidbodyBaseEditor` so it now derives from `NetcodeEditorBase`. (#3013)
3540
- Changed `NetworkManagerEditor` so it now derives from `NetcodeEditorBase`. (#3013)

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Unity.Netcode.Editor
99
/// </summary>
1010
[CustomEditor(typeof(NetworkTransform), true)]
1111
[CanEditMultipleObjects]
12-
public class NetworkTransformEditor : NetcodeEditorBase<NetworkBehaviour>
12+
public class NetworkTransformEditor : NetcodeEditorBase<NetworkTransform>
1313
{
1414
private SerializedProperty m_SwitchTransformSpaceWhenParented;
1515
private SerializedProperty m_TickSyncChildren;

com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ public override void OnDestroy()
584584
base.OnDestroy();
585585
}
586586

587-
private void Awake()
587+
protected virtual void Awake()
588588
{
589589
int layers = m_Animator.layerCount;
590590
// Initializing the below arrays for everyone handles an issue

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3604,8 +3604,12 @@ private void SetStateServerRpc(Vector3 pos, Quaternion rot, Vector3 scale, bool
36043604
}
36053605

36063606
/// <summary>
3607-
/// Teleport the transform to the given values without interpolating
3607+
/// Teleport an already spawned object to the given values without interpolating.
36083608
/// </summary>
3609+
/// <remarks>
3610+
/// This is intended to be used on already spawned objects, for setting the position of a dynamically spawned object just apply the transform values prior to spawning. <br />
3611+
/// With player objects, override the <see cref="OnNetworkSpawn"/> method and have the authority make adjustments to the transform prior to invoking base.OnNetworkSpawn.
3612+
/// </remarks>
36093613
/// <param name="newPosition"></param> new position to move to.
36103614
/// <param name="newRotation"></param> new rotation to rotate to.
36113615
/// <param name="newScale">new scale to scale to.</param>

com.unity.netcode.gameobjects/Runtime/Connection/NetworkConnectionManager.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1299,7 +1299,15 @@ internal void DisconnectClient(ulong clientId, string reason = null)
12991299
{
13001300
if (!LocalClient.IsServer)
13011301
{
1302-
throw new NotServerException($"Only server can disconnect remote clients. Please use `{nameof(Shutdown)}()` instead.");
1302+
if (NetworkManager.NetworkConfig.NetworkTopology == NetworkTopologyTypes.ClientServer)
1303+
{
1304+
throw new NotServerException($"Only server can disconnect remote clients. Please use `{nameof(Shutdown)}()` instead.");
1305+
}
1306+
else
1307+
{
1308+
Debug.LogWarning($"Currently, clients cannot disconnect other clients from a distributed authority session. Please use `{nameof(Shutdown)}()` instead.");
1309+
return;
1310+
}
13031311
}
13041312

13051313
if (clientId == NetworkManager.ServerClientId)

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,7 @@ private bool InternalHasAuthority()
938938
/// <summary>
939939
/// If true, the object will always be replicated as root on clients and the parent will be ignored.
940940
/// </summary>
941+
[Tooltip("If enabled (default disabled), instances of this NetworkObject will ignore any parent(s) it might have and replicate on clients as the root being its parent.")]
941942
public bool AlwaysReplicateAsRoot;
942943

943944
/// <summary>
@@ -955,6 +956,8 @@ private bool InternalHasAuthority()
955956
/// bandwidth cost. This can also be useful for UI elements that have
956957
/// a predetermined fixed position.
957958
/// </remarks>
959+
[Tooltip("If enabled (default enabled), newly joining clients will be synchronized with the transform of the associated GameObject this component is attached to. Typical use case" +
960+
" scenario would be for managment objects or in-scene placed objects that don't move and already have their transform settings applied within the scene information.")]
958961
public bool SynchronizeTransform = true;
959962

960963
/// <summary>
@@ -1012,6 +1015,7 @@ public void SetSceneObjectStatus(bool isSceneObject = false)
10121015
/// To synchronize clients of a <see cref="NetworkObject"/>'s scene being changed via <see cref="SceneManager.MoveGameObjectToScene(GameObject, Scene)"/>,
10131016
/// make sure <see cref="SceneMigrationSynchronization"/> is enabled (it is by default).
10141017
/// </remarks>
1018+
[Tooltip("When enabled (default disabled), spawned instances of this NetworkObject will automatically migrate to any newly assigned active scene.")]
10151019
public bool ActiveSceneSynchronization;
10161020

10171021
/// <summary>
@@ -1030,6 +1034,7 @@ public void SetSceneObjectStatus(bool isSceneObject = false)
10301034
/// is <see cref="true"/> and <see cref="ActiveSceneSynchronization"/> is <see cref="false"/> and the scene is not the currently
10311035
/// active scene, then the <see cref="NetworkObject"/> will be destroyed.
10321036
/// </remarks>
1037+
[Tooltip("When enabled (default enabled), dynamically spawned instances of this NetworkObject's migration to a different scene will automatically be synchonize amongst clients.")]
10331038
public bool SceneMigrationSynchronization = true;
10341039

10351040
/// <summary>
@@ -1045,7 +1050,7 @@ public void SetSceneObjectStatus(bool isSceneObject = false)
10451050
/// <summary>
10461051
/// When set to false, the NetworkObject will be spawned with no observers initially (other than the server)
10471052
/// </summary>
1048-
[Tooltip("When false, the NetworkObject will spawn with no observers initially. (default is true)")]
1053+
[Tooltip("When disabled (default enabled), the NetworkObject will spawn with no observers. You control object visibility using NetworkShow. This applies to newly joining clients as well.")]
10491054
public bool SpawnWithObservers = true;
10501055

10511056
/// <summary>
@@ -1074,11 +1079,13 @@ public void SetSceneObjectStatus(bool isSceneObject = false)
10741079
/// Whether or not to destroy this object if it's owner is destroyed.
10751080
/// If true, the objects ownership will be given to the server.
10761081
/// </summary>
1082+
[Tooltip("When enabled (default disabled), instances of this NetworkObject will not be destroyed if the owning client disconnects.")]
10771083
public bool DontDestroyWithOwner;
10781084

10791085
/// <summary>
10801086
/// Whether or not to enable automatic NetworkObject parent synchronization.
10811087
/// </summary>
1088+
[Tooltip("When disabled (default enabled), NetworkObject parenting will not be automatically synchronized. This is typically used when you want to implement your own custom parenting solution.")]
10821089
public bool AutoObjectParentSync = true;
10831090

10841091
/// <summary>
@@ -1091,12 +1098,14 @@ public void SetSceneObjectStatus(bool isSceneObject = false)
10911098
/// When using a <see cref="NetworkTopologyTypes.ClientServer"/> network topology and an owner authoritative motion model, disabling this can help smooth parenting transitions.
10921099
/// When using a <see cref="NetworkTopologyTypes.DistributedAuthority"/> network topology this will have no impact on the owner's instance since only the authority/owner can parent.
10931100
/// </remarks>
1101+
[Tooltip("When disabled (default enabled), the owner will not apply a server or host's transform properties when parenting changes. Primarily useful for client-server network topology configurations.")]
10941102
public bool SyncOwnerTransformWhenParented = true;
10951103

10961104
/// <summary>
10971105
/// Client-Server specific, when enabled an owner of a NetworkObject can parent locally as opposed to requiring the owner to notify the server it would like to be parented.
10981106
/// This behavior is always true when using a distributed authority network topology and does not require it to be set.
10991107
/// </summary>
1108+
[Tooltip("When enabled (default disabled), owner's can parent a NetworkObject locally without having to send an RPC to the server or host. Only pertinent when using client-server network topology configurations.")]
11001109
public bool AllowOwnerToParent;
11011110

11021111
internal readonly HashSet<ulong> Observers = new HashSet<ulong>();

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/ProxyMessage.cs

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using Unity.Collections;
32

43
namespace Unity.Netcode
@@ -34,21 +33,13 @@ public unsafe void Handle(ref NetworkContext context)
3433
var networkManager = (NetworkManager)context.SystemOwner;
3534
if (!networkManager.SpawnManager.SpawnedObjects.TryGetValue(WrappedMessage.Metadata.NetworkObjectId, out var networkObject))
3635
{
37-
// With distributed authority mode, we can send Rpcs before we have been notified the NetworkObject is despawned.
38-
// DANGO-TODO: Should the CMB Service cull out any Rpcs targeting recently despawned NetworkObjects?
39-
// DANGO-TODO: This would require the service to keep track of despawned NetworkObjects since we re-use NetworkObject identifiers.
40-
if (networkManager.DistributedAuthorityMode)
36+
// If the NetworkObject no longer exists then just log a warning when developer mode logging is enabled and exit.
37+
// This can happen if NetworkObject is despawned and a client sends an RPC before receiving the despawn message.
38+
if (networkManager.LogLevel == LogLevel.Developer)
4139
{
42-
if (networkManager.LogLevel == LogLevel.Developer)
43-
{
44-
NetworkLog.LogWarning($"[{WrappedMessage.Metadata.NetworkObjectId}, {WrappedMessage.Metadata.NetworkBehaviourId}, {WrappedMessage.Metadata.NetworkRpcMethodId}]An RPC called on a {nameof(NetworkObject)} that is not in the spawned objects list. Please make sure the {nameof(NetworkObject)} is spawned before calling RPCs.");
45-
}
46-
return;
47-
}
48-
else
49-
{
50-
throw new InvalidOperationException($"[{WrappedMessage.Metadata.NetworkObjectId}, {WrappedMessage.Metadata.NetworkBehaviourId}, {WrappedMessage.Metadata.NetworkRpcMethodId}]An RPC called on a {nameof(NetworkObject)} that is not in the spawned objects list. Please make sure the {nameof(NetworkObject)} is spawned before calling RPCs.");
40+
NetworkLog.LogWarning($"[{WrappedMessage.Metadata.NetworkObjectId}, {WrappedMessage.Metadata.NetworkBehaviourId}, {WrappedMessage.Metadata.NetworkRpcMethodId}] An RPC called on a {nameof(NetworkObject)} that is not in the spawned objects list. Please make sure the {nameof(NetworkObject)} is spawned before calling RPCs.");
5141
}
42+
return;
5243
}
5344

5445
var observers = networkObject.Observers;

com.unity.netcode.gameobjects/Runtime/Messaging/Messages/RpcMessages.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,13 @@ public static void Handle(ref NetworkContext context, ref RpcMetadata metadata,
6060
var networkManager = (NetworkManager)context.SystemOwner;
6161
if (!networkManager.SpawnManager.SpawnedObjects.TryGetValue(metadata.NetworkObjectId, out var networkObject))
6262
{
63-
throw new InvalidOperationException($"An RPC called on a {nameof(NetworkObject)} that is not in the spawned objects list. Please make sure the {nameof(NetworkObject)} is spawned before calling RPCs.");
63+
// If the NetworkObject no longer exists then just log a warning when developer mode logging is enabled and exit.
64+
// This can happen if NetworkObject is despawned and a client sends an RPC before receiving the despawn message.
65+
if (networkManager.LogLevel == LogLevel.Developer)
66+
{
67+
NetworkLog.LogWarning($"[{metadata.NetworkObjectId}, {metadata.NetworkBehaviourId}, {metadata.NetworkRpcMethodId}] An RPC called on a {nameof(NetworkObject)} that is not in the spawned objects list. Please make sure the {nameof(NetworkObject)} is spawned before calling RPCs.");
68+
}
69+
return;
6470
}
6571
var networkBehaviour = networkObject.GetNetworkBehaviourAtOrderIndex(metadata.NetworkBehaviourId);
6672

0 commit comments

Comments
 (0)