fix: reset static fields for Fast Enter Play Mode#3956
Conversation
# Conflicts: # com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs
| } | ||
|
|
||
| internal static bool LogSerializationOrder = false; | ||
| internal static bool LogSerializationOrder; |
There was a problem hiding this comment.
This is only used to perform some logging but it is never set to true and it is internal, should we keep it? Is this something that should go in the new logging system instead?
There was a problem hiding this comment.
If you can figure out a way to handle it via the new logging system that would be great.
Otherwise, you could get rid of the static and just wrap that code in a define (i.e. LOG_SERIALIZATION_ORDER or the like).
There was a problem hiding this comment.
Let's just move this setting into NetworkLog.Config We can change the log logic later
There was a problem hiding this comment.
When is m_ParentedChildren updated? I had a warning about this in my IDE and didn't find the info myself 🫠
There was a problem hiding this comment.
Yeah... that was evidently a legacy merge issue that kept the old way of handling this.
As an example:
// Synchronize any nested NetworkTransforms with the parent's <<---- The new "correct" way
foreach (var childNetworkTransform in NetworkObject.NetworkTransforms)
{
// Don't update the same instance or any nested NetworkTransform with a different authority mode
if (childNetworkTransform == this || childNetworkTransform.AuthorityMode != AuthorityMode)
{
continue;
}
if (childNetworkTransform.CanCommitToTransform)
{
childNetworkTransform.OnNetworkTick(true);
}
}
// Synchronize any parented children with the parent's motion <<---- The legacy "old way" (remove)
foreach (var child in m_ParentedChildren)
{
// Synchronize any nested NetworkTransforms of the child with the parent's
foreach (var childNetworkTransform in child.NetworkTransforms)
{
if (childNetworkTransform.CanCommitToTransform)
{
childNetworkTransform.OnNetworkTick(true);
}
}
}Everywhere you see m_ParentedChildren (merge artifact) there is going to be a duplicate for loop using NetworkObject.NetworkTransforms (correct).
simon-lemay-unity
left a comment
There was a problem hiding this comment.
Changes to UnityTransport look good to me.
# Conflicts: # com.unity.netcode.gameobjects/Runtime/Logging/NetworkLog.cs
|
|
||
| #if UNITY_EDITOR | ||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
| private static void ResetStaticsOnLoad() |
There was a problem hiding this comment.
Move this at the top
| @@ -44,6 +44,10 @@ public static class QuaternionCompressor | |||
|
|
|||
| // Used to store the absolute value of the 4 quaternion elements | |||
| private static Quaternion s_QuatAbsValues = Quaternion.identity; | |||
There was a problem hiding this comment.
Replace quaternion by 4 ints
| #if UNITY_EDITOR | ||
| using UnityEngine; | ||
| #endif |
There was a problem hiding this comment.
Remove this, add UnityEngine.Runtime...
| internal delegate void ResetNetworkManagerDelegate(NetworkManager manager); | ||
|
|
||
| internal static ResetNetworkManagerDelegate OnNetworkManagerReset; | ||
| //We already are in an #if UNITY_ENGINE def |
There was a problem hiding this comment.
Remove this comment
| DisableNotOptimizedSerializedType = false; | ||
| } | ||
|
|
||
| private void Reset() |
There was a problem hiding this comment.
Add xml doc with:
Used by cref... NetworkManagerHeper this is called by the reset button of the Unity Editor
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
| private static void Initialize() | ||
| { | ||
| #if UNITY_EDITOR |
There was a problem hiding this comment.
add comment //Reset Statics
| using System.Collections.Generic; | ||
| using Unity.Collections; | ||
| #if UNITY_EDITOR | ||
| using UnityEngine; |
There was a problem hiding this comment.
Move it down to use UnityEngine.Runtime...
| @@ -1,3 +1,6 @@ | |||
| #if UNITY_6000_6_OR_NEWER | |||
| using Unity.Scripting.LifecycleManagement; | |||
There was a problem hiding this comment.
Add it down Unity.Scripting.LifecycleManagement.Auto...
| s_SceneEventTypeNames[(uint)type] = type.ToString(); | ||
| } | ||
| s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame"); | ||
| } |
There was a problem hiding this comment.
Remove this reset, not needed here
| @@ -13,6 +16,18 @@ internal class NetworkMetrics : INetworkMetrics | |||
| private const ulong k_MaxMetricsPerFrame = 1000L; | |||
| private static Dictionary<uint, string> s_SceneEventTypeNames; | |||
There was a problem hiding this comment.
this can be made readonly
| using Unity.Collections.LowLevel.Unsafe; | ||
| using Unity.Mathematics; | ||
| #if UNITY_6000_6_OR_NEWER | ||
| using Unity.Scripting.LifecycleManagement; |
There was a problem hiding this comment.
Put this with AutoStaticsCleanup
| @@ -1,4 +1,7 @@ | |||
| using System; | |||
| #if UNITY_6000_6_OR_NEWER | |||
| using Unity.Scripting.LifecycleManagement; | |||
| public static class NetworkVariableSerializationTypedInitializers | ||
| { | ||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterAssembliesLoaded)] | ||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] |
There was a problem hiding this comment.
Do not change this one
| internal static bool IgnoreInitializeWarning; | ||
| #if UNITY_EDITOR | ||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
| private static void ResetStaticsOnLoad() => IgnoreInitializeWarning = false; |
There was a problem hiding this comment.
The test lifecycle cleans itself up, we can remove this one
| #if UNITY_EDITOR | ||
| internal static void ResetInstances() => s_Instances = new Dictionary<NetworkManager, List<SceneUnloadEventHandler>>(); | ||
| #endif |
There was a problem hiding this comment.
Because we're not using the attribute, a conditional define works here
| #if UNITY_EDITOR | |
| internal static void ResetInstances() => s_Instances = new Dictionary<NetworkManager, List<SceneUnloadEventHandler>>(); | |
| #endif | |
| [Conditional("UNITY_EDITOR")] | |
| internal static void ResetInstances() => s_Instances = new Dictionary<NetworkManager, List<SceneUnloadEventHandler>>(); |
| @@ -636,7 +641,7 @@ internal void WriteSceneSynchronizationData(FastBufferWriter writer) | |||
| } | |||
| if (EnableSerializationLogs) | |||
There was a problem hiding this comment.
Move this one too to the NetworkLog LogConfiguration struct
There was a problem hiding this comment.
Add a code comment showing where it is used
Purpose of this PR
Ensure com.unity.netcode.gameobjects package supports Fast Enter Play Mode
Jira ticket
MTT-14665
Changelog
Documentation
Testing & QA (How your changes can be verified during release Playtest)
Functional Testing
Manual testing :
Manual testing doneAutomated tests:
Covered by existing automated testsCovered by new automated testsDoes the change require QA team to:
Review automated tests?Execute manual tests?Provide feedback about the PR?If any boxes above are checked the QA team will be automatically added as a PR reviewer.
Backports
N/A