Skip to content

Commit 80b2353

Browse files
authored
Merge branch 'develop-2.0.0' into fix/rust-tests
2 parents f139721 + a31fee7 commit 80b2353

File tree

6 files changed

+193
-131
lines changed

6 files changed

+193
-131
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,18 @@ Additional documentation and release notes are available at [Multiplayer Documen
1313

1414
### Changed
1515

16-
- Improve performance of `NetworkBehaviour`. (#3915)
17-
- Improve performance of `NetworkTransform`. (#3907)
18-
- Improve performance of `NetworkRigidbodyBase`. (#3906)
19-
- Improve performance of `NetworkAnimator`. (#3905)
16+
- Replaced Debug usage by NetcodeLog on `NetworkSpawnManager` and `NetworkObject`. (#3933)
17+
- Improved performance of `NetworkBehaviour`. (#3915)
18+
- Improved performance of `NetworkTransform`. (#3907)
19+
- Improved performance of `NetworkRigidbodyBase`. (#3906)
20+
- Improved performance of `NetworkAnimator`. (#3905)
2021

2122
### Deprecated
2223

2324

2425
### Removed
2526

27+
- Removed un-needed exceptions on `NetworkSpawnManager`. (#3933)
2628

2729
### Fixed
2830

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

Lines changed: 67 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ internal void OnValidate()
297297
if (globalId.identifierType != k_SceneObjectType)
298298
{
299299
// This should never happen, but in the event it does throw and error.
300-
Debug.LogError($"[{gameObject.name}] is detected as an in-scene placed object but its identifier is of type {globalId.identifierType}! **Report this error**");
300+
NetworkLog.LogError($"[{gameObject.name}] is detected as an in-scene placed object but its identifier is of type {globalId.identifierType}! **Report this error**");
301301
}
302302

303303
// If this is a prefab instance, then we want to mark it as having been updated in order for the udpated GlobalObjectIdHash value to be saved.
@@ -1762,23 +1762,25 @@ internal void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool pla
17621762
{
17631763
NetworkLog.LogError($"[{name}] When distributed authority mode is enabled, you can only spawn NetworkObjects that belong to the local instance! Local instance id {NetworkManagerOwner.LocalClientId} is not the same as the assigned owner id: {ownerClientId}!");
17641764
}
1765-
return;
17661765
}
17671766
else
17681767
{
17691768
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
17701769
{
17711770
NetworkLog.LogError($"[{name}] Only server can spawn {nameof(NetworkObject)}s.");
17721771
}
1773-
return;
17741772
}
1773+
return;
17751774
}
17761775

17771776
if (NetworkManagerOwner.DistributedAuthorityMode)
17781777
{
17791778
if (NetworkManagerOwner.LocalClient == null || !NetworkManagerOwner.IsConnectedClient || !NetworkManagerOwner.ConnectionManager.LocalClient.IsApproved)
17801779
{
1781-
Debug.LogError($"Cannot spawn {name} until the client is fully connected to the session!");
1780+
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
1781+
{
1782+
NetworkLog.LogError($"Cannot spawn {name} until the client is fully connected to the session!");
1783+
}
17821784
return;
17831785
}
17841786
if (NetworkManagerOwner.NetworkConfig.EnableSceneManagement)
@@ -1842,7 +1844,10 @@ internal void SpawnInternal(bool destroyWithScene, ulong ownerClientId, bool pla
18421844
}
18431845
else
18441846
{
1845-
NetworkLog.LogWarningServer($"[{name}] Ran into unknown conditional check during spawn when determining distributed authority mode or not");
1847+
if (NetworkManagerOwner.LogLevel <= LogLevel.Normal)
1848+
{
1849+
NetworkLog.LogWarningServer($"[{name}] Ran into unknown conditional check during spawn when determining distributed authority mode or not");
1850+
}
18461851
}
18471852
}
18481853

@@ -1864,7 +1869,10 @@ public static NetworkObject InstantiateAndSpawn(GameObject networkPrefab, Networ
18641869
var networkObject = networkPrefab.GetComponent<NetworkObject>();
18651870
if (networkObject == null)
18661871
{
1867-
Debug.LogError($"The {nameof(NetworkPrefab)} {networkPrefab.name} does not have a {nameof(NetworkObject)} component!");
1872+
if (networkManager.LogLevel <= LogLevel.Error)
1873+
{
1874+
NetworkLog.LogError($"The {nameof(NetworkPrefab)} {networkPrefab.name} does not have a {nameof(NetworkObject)} component!");
1875+
}
18681876
return null;
18691877
}
18701878
return networkObject.InstantiateAndSpawn(networkManager, ownerClientId, destroyWithScene, isPlayerObject, forceOverride, position, rotation);
@@ -1886,34 +1894,49 @@ public NetworkObject InstantiateAndSpawn(NetworkManager networkManager, ulong ow
18861894
{
18871895
if (networkManager == null)
18881896
{
1889-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NetworkManagerNull]);
1897+
if (NetworkManager.LogLevel <= LogLevel.Error)
1898+
{
1899+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NetworkManagerNull]);
1900+
}
18901901
return null;
18911902
}
18921903

18931904
if (!networkManager.IsListening)
18941905
{
1895-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NoActiveSession]);
1906+
if (networkManager.LogLevel <= LogLevel.Error)
1907+
{
1908+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NoActiveSession]);
1909+
}
18961910
return null;
18971911
}
18981912

18991913
ownerClientId = networkManager.DistributedAuthorityMode ? networkManager.LocalClientId : ownerClientId;
19001914
// We only need to check for authority when running in client-server mode
19011915
if (!networkManager.IsServer && !networkManager.DistributedAuthorityMode)
19021916
{
1903-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotAuthority]);
1917+
if (networkManager.LogLevel <= LogLevel.Error)
1918+
{
1919+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotAuthority]);
1920+
}
19041921
return null;
19051922
}
19061923

19071924
if (networkManager.ShutdownInProgress)
19081925
{
1909-
Debug.LogWarning(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.InvokedWhenShuttingDown]);
1926+
if (networkManager.LogLevel <= LogLevel.Normal)
1927+
{
1928+
NetworkLog.LogWarning(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.InvokedWhenShuttingDown]);
1929+
}
19101930
return null;
19111931
}
19121932

19131933
// Verify it is actually a valid prefab
19141934
if (!networkManager.NetworkConfig.Prefabs.Contains(gameObject))
19151935
{
1916-
Debug.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotRegisteredNetworkPrefab]);
1936+
if (networkManager.LogLevel <= LogLevel.Error)
1937+
{
1938+
NetworkLog.LogError(NetworkSpawnManager.InstantiateAndSpawnErrors[NetworkSpawnManager.InstantiateAndSpawnErrorTypes.NotRegisteredNetworkPrefab]);
1939+
}
19171940
return null;
19181941
}
19191942

@@ -1969,7 +1992,6 @@ public void Despawn(bool destroy = true)
19691992
{
19701993
NetworkLog.LogErrorServer($"[{name}][Attempted despawn before {nameof(NetworkObject)} was spawned]");
19711994
}
1972-
19731995
return;
19741996
}
19751997

@@ -2019,10 +2041,8 @@ public void ChangeOwnership(ulong newOwnerClientId)
20192041
{
20202042
NetworkLog.LogErrorServer($"[{name}][Attempted ownership change before {nameof(NetworkObject)} was spawned]");
20212043
}
2022-
20232044
return;
20242045
}
2025-
20262046
NetworkManagerOwner.SpawnManager.ChangeOwnership(this, newOwnerClientId, HasAuthority);
20272047
}
20282048

@@ -2038,7 +2058,6 @@ internal void InvokeBehaviourOnOwnershipChanged(ulong originalOwnerClientId, ulo
20382058
{
20392059
NetworkLog.LogErrorServer($"[{name}][Attempted behavior invoke on ownership changed before {nameof(NetworkObject)} was spawned]");
20402060
}
2041-
20422061
return;
20432062
}
20442063

@@ -2069,10 +2088,12 @@ internal void InvokeBehaviourOnOwnershipChanged(ulong originalOwnerClientId, ulo
20692088
{
20702089
if (!childBehaviour.gameObject.activeInHierarchy)
20712090
{
2072-
Debug.LogWarning($"[{name}] {childBehaviour.gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during ownership assignment!");
2091+
if (NetworkManagerOwner.LogLevel <= LogLevel.Normal)
2092+
{
2093+
NetworkLog.LogWarning($"[{name}] {childBehaviour.gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {childBehaviour.GetType().Name} component was skipped during ownership assignment!");
2094+
}
20732095
continue;
20742096
}
2075-
20762097
childBehaviour.InternalOnGainedOwnership();
20772098
}
20782099
}
@@ -2088,7 +2109,10 @@ internal void InvokeOwnershipChanged(ulong previous, ulong next)
20882109
}
20892110
else
20902111
{
2091-
Debug.LogWarning($"[{name}] {ChildNetworkBehaviours[i].gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {ChildNetworkBehaviours[i].GetType().Name} component was skipped during ownership assignment!");
2112+
if (NetworkManagerOwner.LogLevel <= LogLevel.Normal)
2113+
{
2114+
NetworkLog.LogWarning($"[{name}] {ChildNetworkBehaviours[i].gameObject.name} is disabled! Netcode for GameObjects does not support disabled NetworkBehaviours! The {ChildNetworkBehaviours[i].GetType().Name} component was skipped during ownership assignment!");
2115+
}
20922116
}
20932117
}
20942118
}
@@ -2284,7 +2308,7 @@ internal bool InternalTrySetParent(NetworkObject parent, bool worldPositionStays
22842308
private void OnTransformParentChanged()
22852309
{
22862310
var networkManager = NetworkManager;
2287-
if (!AutoObjectParentSync || networkManager.ShutdownInProgress)
2311+
if (!AutoObjectParentSync || (networkManager != null && networkManager.ShutdownInProgress))
22882312
{
22892313
return;
22902314
}
@@ -2296,18 +2320,9 @@ private void OnTransformParentChanged()
22962320

22972321
if (networkManager == null || !networkManager.IsListening)
22982322
{
2299-
// DANGO-TODO: Review as to whether we want to provide a better way to handle changing parenting of objects when the
2300-
// object is not spawned. Really, we shouldn't care about these types of changes.
2301-
if (networkManager.DistributedAuthorityMode && m_CachedParent != null && transform.parent == null)
2302-
{
2303-
m_CachedParent = null;
2304-
return;
2305-
}
23062323
transform.parent = m_CachedParent;
2307-
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
2308-
{
2309-
NetworkLog.LogError($"[{name}] {nameof(networkManager)} is not listening, start a server or host before re-parenting.");
2310-
}
2324+
// We want to log at any LogLevel, since we may not have a network manager may here.
2325+
NetworkLog.LogError($"[{name}] {nameof(networkManager)} is not listening, start a server or host before re-parenting.");
23112326
return;
23122327
}
23132328

@@ -2324,7 +2339,7 @@ private void OnTransformParentChanged()
23242339
else
23252340
{
23262341
transform.parent = m_CachedParent;
2327-
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
2342+
if (networkManager.LogLevel <= LogLevel.Error)
23282343
{
23292344
NetworkLog.LogErrorServer($"[{name}] {nameof(NetworkObject)} can only be re-parented after being spawned!");
23302345
}
@@ -2361,17 +2376,17 @@ private void OnTransformParentChanged()
23612376
{
23622377
transform.parent = m_CachedParent;
23632378
AuthorityAppliedParenting = false;
2364-
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
2379+
if (networkManager.LogLevel <= LogLevel.Error)
23652380
{
23662381
NetworkLog.LogErrorServer($"[{name}] Invalid parenting, {nameof(NetworkObject)} moved under a non-{nameof(NetworkObject)} parent");
23672382
}
23682383
return;
23692384
}
2370-
else if (!parentObject.IsSpawned)
2385+
if (!parentObject.IsSpawned)
23712386
{
23722387
transform.parent = m_CachedParent;
23732388
AuthorityAppliedParenting = false;
2374-
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
2389+
if (networkManager.LogLevel <= LogLevel.Error)
23752390
{
23762391
NetworkLog.LogErrorServer($"[{name}] {nameof(NetworkObject)} can only be re-parented under another spawned {nameof(NetworkObject)}.");
23772392
}
@@ -2507,10 +2522,10 @@ internal bool ApplyNetworkParenting(bool removeParent = false, bool ignoreNotSpa
25072522
}
25082523
}
25092524

2510-
// If we are removing the parent or our latest parent is not set, then remove the parent
2525+
// If we are removing the parent or our latest parent is not set, then remove the parent.
25112526
// removeParent is only set when:
25122527
// - The server-side NetworkObject.OnTransformParentChanged is invoked and the parent is being removed
2513-
// - The client-side when handling a ParentSyncMessage
2528+
// - The client-side is handling a ParentSyncMessage
25142529
// When clients are synchronizing only the m_LatestParent.HasValue will not have a value if there is no parent
25152530
// or a parent was removed prior to the client connecting (i.e. in-scene placed NetworkObjects)
25162531
if (removeParent || !m_LatestParent.HasValue)
@@ -2610,7 +2625,10 @@ internal void InvokeBehaviourNetworkSpawn()
26102625
{
26112626
if (!childBehaviour.gameObject.activeInHierarchy)
26122627
{
2613-
Debug.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}");
2628+
if (NetworkManager.LogLevel <= LogLevel.Normal)
2629+
{
2630+
NetworkLog.LogWarning($"{GenerateDisabledNetworkBehaviourWarning(childBehaviour)}");
2631+
}
26142632
continue;
26152633
}
26162634
childBehaviour.NetworkSpawn();
@@ -2722,7 +2740,6 @@ internal List<NetworkBehaviour> ChildNetworkBehaviours
27222740
}
27232741
#endif
27242742
}
2725-
27262743
return m_ChildNetworkBehaviours;
27272744
}
27282745
}
@@ -2889,9 +2906,7 @@ internal struct SerializedObject
28892906
public bool HasParent;
28902907
public bool IsSceneObject;
28912908
public bool HasTransform;
2892-
28932909
public bool IsLatestParentSet;
2894-
28952910
public bool WorldPositionStays;
28962911

28972912
/// <summary>
@@ -2901,15 +2916,10 @@ internal struct SerializedObject
29012916
/// to the current active scene when its scene is unloaded. (only for dynamically spawned)
29022917
/// </summary>
29032918
public bool DestroyWithScene;
2904-
29052919
public bool DontDestroyWithOwner;
2906-
29072920
public bool HasOwnershipFlags;
2908-
29092921
public bool SyncObservers;
2910-
29112922
public bool SpawnWithObservers;
2912-
29132923
public bool HasInstantiationData;
29142924

29152925
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -3001,9 +3011,6 @@ public struct TransformData : INetworkSerializeByMemcpy
30013011

30023012
public TransformData Transform;
30033013

3004-
//If(Metadata.IsReparented)
3005-
3006-
//If(IsLatestParentSet)
30073014
public ulong? LatestParent;
30083015

30093016
public NetworkObject OwnerObject;
@@ -3324,19 +3331,19 @@ internal static NetworkObject Deserialize(in SerializedObject serializedObject,
33243331
// Ensure this is done whether the spawn succeeds or fails
33253332
networkManager.DeferredMessageManager.ProcessTriggers(IDeferredNetworkMessageManager.TriggerType.OnSpawn, networkObject.NetworkObjectId);
33263333

3327-
// If the SpawnManager spawn doesn't succeed, be sure to clean up
3328-
if (!succeeded)
3334+
// Ensure that the buffer is completely reset
3335+
if (reader.Position != endOfSynchronizationData)
33293336
{
3330-
// Ensure that the buffer is completely reset
3331-
if (reader.Position != endOfSynchronizationData)
3337+
if (networkManager.LogLevel <= LogLevel.Normal)
33323338
{
3333-
if (networkManager.LogLevel <= LogLevel.Normal)
3334-
{
3335-
NetworkLog.LogWarning($"[{networkObject.name}][Deserialize][Size mismatch] Expected: {endOfSynchronizationData} Currently At: {reader.Position}!");
3336-
}
3337-
reader.Seek(endOfSynchronizationData);
3339+
NetworkLog.LogWarning($"[{networkObject.name}][Deserialize][{nameof(NetworkBehaviour)}Synchronization][Size mismatch] Expected: {endOfSynchronizationData} Currently At: {reader.Position}!");
33383340
}
3341+
reader.Seek(endOfSynchronizationData);
3342+
}
33393343

3344+
// If the SpawnManager spawn doesn't succeed, be sure to clean up
3345+
if (!succeeded)
3346+
{
33403347
// If the networkObject was created but the spawn failed, the created object needs to be destroyed
33413348
if (networkObject != null)
33423349
{
@@ -3583,17 +3590,13 @@ internal uint CheckForGlobalObjectIdHashOverride()
35833590
{
35843591
return PrefabGlobalObjectIdHash;
35853592
}
3586-
else
3593+
// For legacy manual instantiation and spawning, check the OverrideToNetworkPrefab for a possible match
3594+
if (networkManager.NetworkConfig.Prefabs.OverrideToNetworkPrefab.TryGetValue(GlobalObjectIdHash, out var overrideHash))
35873595
{
3588-
// For legacy manual instantiation and spawning, check the OverrideToNetworkPrefab for a possible match
3589-
if (networkManager.NetworkConfig.Prefabs.OverrideToNetworkPrefab.ContainsKey(GlobalObjectIdHash))
3590-
{
3591-
return networkManager.NetworkConfig.Prefabs.OverrideToNetworkPrefab[GlobalObjectIdHash];
3592-
}
3596+
return overrideHash;
35933597
}
35943598
}
35953599
}
3596-
35973600
return GlobalObjectIdHash;
35983601
}
35993602

0 commit comments

Comments
 (0)