Skip to content

fix: reset static fields for Fast Enter Play Mode#3956

Open
noellie-velez wants to merge 29 commits into
develop-2.0.0from
chore/fast-enter-playmode
Open

fix: reset static fields for Fast Enter Play Mode#3956
noellie-velez wants to merge 29 commits into
develop-2.0.0from
chore/fast-enter-playmode

Conversation

@noellie-velez
Copy link
Copy Markdown
Collaborator

@noellie-velez noellie-velez commented Apr 24, 2026

Purpose of this PR

Ensure com.unity.netcode.gameobjects package supports Fast Enter Play Mode

Jira ticket

MTT-14665

Changelog

  • Fixed: Netcode for Game Objects now supports Fast Enter Play Mode

Documentation

  • No documentation changes or additions were necessary.

Testing & QA (How your changes can be verified during release Playtest)

Functional Testing

Manual testing :

  • Manual testing done

Automated tests:

  • Covered by existing automated tests
  • Covered by new automated tests

Does 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

Comment thread com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs Outdated
@noellie-velez noellie-velez marked this pull request as ready for review April 24, 2026 15:06
@noellie-velez noellie-velez requested review from a team as code owners April 24, 2026 15:06
Copy link
Copy Markdown
Contributor

@simon-lemay-unity simon-lemay-unity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes to UnityTransport look good to me.

Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkTransform.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Components/QuaternionCompressor.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/ComponentFactory.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Core/NetworkManager.cs
Comment thread com.unity.netcode.gameobjects/Runtime/Messaging/DeferredMessageManager.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Messaging/INetworkMessage.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Metrics/NetworkMetrics.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/NetworkVariable/NetworkVariableBase.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/SceneManagement/SceneEventData.cs Outdated
Comment thread com.unity.netcode.gameobjects/Runtime/Components/NetworkAnimator.cs
Copy link
Copy Markdown
Member

@EmandM EmandM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking incredible! You've done such good thorough work on this PR. You should be really proud of yourself. :godmode:

IsDestroying = true;
}

private void OnDisable()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unsubscribe should be in OnDestroy instead. It is (kind of vaguely) valid to have a disabled NetworkObject so we should still be tracking that object.

using System;
using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used often enough that the using define still has value in this file. Do you mind putting it back?

s_SceneEventTypeNames[(uint)type] = type.ToString();
k_SceneEventTypeNames[(uint)type] = type.ToString();
}
s_FrameDispatch = new ProfilerMarker($"{nameof(NetworkMetrics)}.DispatchFrame");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never reset so it can match the pattern of k_SceneEventTypeNames. (i.e. static readonly that's only set here).

/// <summary>
/// Command-line options singleton
/// </summary>
public static CommandLineOptions Instance
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something in here is breaking some tests. We maybe don't need to worry about resetting the CommandLineOptions in the editor as command line args are very hard to use from the editor.

I wonder if instead of the usage pattern of CommandLineOptions.Instance.GetArg(<arg>) as string <varName> it'd be nicer to just have a single static function called TryGetArg.

Something like

public static bool TryGetArg(string arg, out string argValue)

That can then be used like

CommandLineOptions.TryGetArg(k_OverridePortArg, out var argValue)

return 0;
}

internal bool EnableSerializationLogs = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field wasn't static. We don't want lose the functionality of being able to turn on logging per client, so might be best to put this one back for this PR.

I'll updated it properly when I implement the new logger through here.

internal class FastEnterPlayModeTests
{
[UnityTest]
public IEnumerator NetworkManagerSingletonResetsOnPlayModeEnter(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't seem to be testing anything.

I know I said we needed tests for this change, but looking at the changes in this PR I think there's not really any risky behaviour being reset here that we need a test to ensure it's reset. So it looks like we might not need a test after all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants