Skip to content

CHANGE: Support entering playmode with Domain Reload disabled ("Faster Enter Playmode")#2343

Open
K-Tone wants to merge 31 commits intodevelopfrom
anthony/faster-enter-playmode
Open

CHANGE: Support entering playmode with Domain Reload disabled ("Faster Enter Playmode")#2343
K-Tone wants to merge 31 commits intodevelopfrom
anthony/faster-enter-playmode

Conversation

@K-Tone
Copy link
Collaborator

@K-Tone K-Tone commented Feb 11, 2026

Description

This branch aims to enable entering the play mode with Domain Reload disabled, it's also called faster enter playmode internally. The change is a bit non-trivial because we seem to have quite a bunch of statics, and resetting them the right way is not always clear to do.

The branch is basically a straightforward merge of the current develop branch into Hakan's #2016 branch, which in turn is based on incredible Tim's original branch: #1915.

Testing status & QA

Barely tested at this stage of affairs, but appears to be running kinda alright on Anthony's mac locally.

Overall Product Risks

  • Complexity: High
  • Halo Effect: High

Comments to reviewers

Please describe any additional information such as what to focus on, or historical info for the reviewers.

Checklist

Before review:

  • Changelog entry added.
    • Explains the change in Changed, Fixed, Added sections.
    • For API change contains an example snippet and/or migration example.
    • JIRA ticket linked, example (case %%). If it is a private issue, just add the case ID without a link.
    • Jira port for the next release set as "Resolved".
  • Tests added/changed, if applicable.
    • Functional tests Area_CanDoX, Area_CanDoX_EvenIfYIsTheCase, Area_WhenIDoX_AndYHappens_ThisIsTheResult.
    • Performance tests.
    • Integration tests.
  • Docs for new/changed API's.
    • Xmldoc cross references are set correctly.
    • Added explanation how the API works.
    • Usage code examples added.
    • The manual is updated, if needed.

During merge:

  • Commit message for squash-merge is prefixed with one of the list:
    • NEW: ___.
    • FIX: ___.
    • DOCS: ___.
    • CHANGE: ___.
    • RELEASE: 1.1.0-preview.3.

timkeo and others added 24 commits June 14, 2024 08:09
- Rework InputSystem's Init functions to handle optional domain reloads
- Bypass InitializeInPlayer() "Reset" and "Restore" functions if DRs disabled

Only the first step to getting this working, but enables FEPM support for golden path scenarios.
- Move Reset/Restore state functionality out of InputSystem to the Test assembly (InputTestStateManager.cs)
- Refactor InputManager Init/Dispose to be cleaner and better abstracted:
    * Adds CreateAndInitialize static method
    * Replaces Destroy() with IDisposable implementation
    * InputManager creates "default" InputSettings object if none provided
    * Runtime, Settings, and Metrics fields now private
- Update InitializeInEditor() to incorporate changes
- Update and fix tests

For the most part, the logic should be mostly preserved. InitializeInEditor() has the biggest (logical)
change because Reset() (moved to Tests) contained some actual init calls that needed to be pulled out.
However, we *should* be making the same calls in the same order.

However, this change does seem to "break" some of the OnScreenTests(); they're now unstable.
This will need to be fixed in a later commit.
- Rework the class so it operates as a Singleton (basically how it's being used)
- Move actions get/set implementations from InputSystem to ProjectWideActions class
    * Combine functionality for tighter cohesion despite being an Editor
    * Update #ifefs to allow Player to access some of these members
- Call EnsureInitialized() from Editor init flows to fix the actual bug

Tested using ProjectWideActions sample and verified could move cube when domain reloads disabled.
Ran Package tests (Edit/Play/Player) to verify no (new) failures.
…ns (ISX-1842)

- Make InputSystem static fields private with read-only accessors
- Add InputSystemTestHooks.cs for "Test Hook" operations that need direct access to fields
- Factor out InputSystemObject (and related State) and rename to InputSystemStateManager
- Factor out "dirty asset tracking" functionality to a separate Utility class

Despite touching a bunch of files, this is a low-risk set of changes; functions are moved
to new files and types renamed, but no real changes to functionality.

Validated changes with Edit/Play/Player tests.
- Most ProjectWideAction changes discarded since feature was re-implemented (no longer relevant)
- Recreate InputSystem "Test Hook" for Enabling/Disabling Actions from tests
- Small fixes from unresolved conflicts or bad merges during rebase
- Various formatting changes (to be more consistant)
- Consolidate functionality into DeferBindingResolutionContext class
- Instantiate Context object as a non-static InputManager field exposed via InputManager methods
- Static field (in each class) initialized via RuntimeInitializeOnLoadMethod() hook
- This functionality is a bit clunky and should be refactored but that's out-of-scope for this work
- Add a flag to guard against re-initializing Plugins within PerformDefaultPluginInitialization()
- Refactor SteamSupport to fix Init/Shutdown flows and improve state management
- Refactor PlayerInput's static fields into a single GlobalState struct (matching other classes)
- Move EnhancedTouch static fields into Touch's GlobalState struct
- Minor refactoring of SteamSupport to improve init/cleanp-up flows (especially with tests)
…ts (ISX-1840)

- Consolidate Touchscreen's cached settings into a separate struct
- Rework NativeInputRuntime initialization to (fully) employ Singleton pattern
- Refactor Actions_CanHandleModification TestCase generator to work without Domain Reloads
- Fix Device static fields not getting reset during SimulateDomainReload()
- Rename some variables
- Add update some comments
- Other small tweaks.
# Conflicts:
#	Packages/com.unity.inputsystem/InputSystem/Actions/InputActionMap.cs
#	Packages/com.unity.inputsystem/InputSystem/Actions/InputActionState.cs
#	Packages/com.unity.inputsystem/InputSystem/InputAnalytics.cs
#	Packages/com.unity.inputsystem/InputSystem/InputManager.cs
#	Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
#	Packages/com.unity.inputsystem/Tests/TestFixture/InputTestFixture.cs
…d from a serialisation thread and force create ScriptableObjects
@K-Tone K-Tone changed the title Anthony/faster enter playmode CHANGE: Support entering playmode with Domain Reload disabled ("Faster Enter Playmode") Feb 18, 2026
@K-Tone K-Tone requested a review from ekcoh February 18, 2026 11:20
@K-Tone
Copy link
Collaborator Author

K-Tone commented Feb 18, 2026

Hey Hakan! Here is my branch that is based on yours really, with just a few minor corrections. Let's take a look at it together and define what are the larger bits of work that are still missing.

@@ -336,7 +336,7 @@ public void UIActionPoint_FiresUIPointEvents_FromInputsMousePenAndTouch(bool use
Update();
if (!useProjectWideActionsAsset)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note to self - wonder if we still need to check for the case where we don't use project-wide input actions. We needed in the Tim's branch but now we only run with project-wide input actions, there's no other way.

}

private int m_DeferredCount;
public bool bindingsNeedResolving; // TODO Revisit: Was previously static, but based on changes by Alex+Tim might no longer be needed?!
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Note to self - figure an answer to this note, and remove it then

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think the answer to this is yes, it's not needed to be static any more because it's part of the context that is now logically single instance.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Or maybe the author of that comment meant that the whole concept is no longer needed? That feels a wrong assumption

// Moreover, later in GlobalInialize we skip initialization specifically in this case.
if (!InputSystem.IsDomainReloadDisabledForPlayMode())
return;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In this function, the early-out is something that I added to fix up the problem where we had a reset right after the static init. Everything below the check is original work by Hakan & Tim.

@K-Tone K-Tone marked this pull request as ready for review February 18, 2026 12:47
@u-pr
Copy link
Contributor

u-pr bot commented Feb 18, 2026

PR Reviewer Guide 🔍

(Review updated until commit 877bb11)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪

The PR involves significant refactoring of core lifecycle management and static state handling to support disabled Domain Reload ("Faster Play Mode"). While the changes are extensive, they follow a consistent pattern of moving static state to managed structures or instance logic.
🏅 Score: 92

The implementation is robust and well-structured, addressing the core challenge of persistent static state by introducing `InputSystemStateManager` and refactoring `InputManager` lifecycle. The inclusion of test hooks and state restoration for tests is a strong addition.
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Initialization Safety

In InitializeInEditor, strictly verify the path where globalReset is false (Fast Play Mode). The code assumes s_Manager is non-null when accessing properties like s_Manager.settings in the else block. While the static constructor guarantees s_Manager creation initially, confirm there are no edge cases (e.g., after a manual cleanup/dispose in tests) where s_Manager could be null here, potentially causing a crash upon entering Play Mode.

else
{
    s_DomainStateManager = ScriptableObject.CreateInstance<InputSystemStateManager>();
    s_DomainStateManager.hideFlags = HideFlags.HideAndDontSave;

    // See if we have a remembered settings object.
    if (EditorBuildSettings.TryGetConfigObject(InputSettingsProvider.kEditorBuildSettingsConfigKey, out InputSettings settingsAsset))
    {
        s_Manager.settings = settingsAsset;
    }
Global State Reset Logic

Verify the condition if (!InputSystem.IsDomainReloadDisabledForPlayMode()) return;. This logic implies that global state is only manually reset when Domain Reload is disabled. Ensure that in the standard case (Domain Reload enabled), the natural clearing of static fields upon reload is sufficient and that this method wasn't previously relied upon for any other initialization setup that might now be skipped.

if (!InputSystem.IsDomainReloadDisabledForPlayMode())
    return;
  • Update review

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@u-pr
Copy link
Contributor

u-pr bot commented Feb 18, 2026

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Fix memory leak in DoInstantiate cleanup

The array clearing logic is incorrect because initPairWithDevicesCount is set to 0
before being used as the length for Array.Clear. This fails to clear references in
the static array, causing a memory leak of InputDevice objects. Swap the order to
clear the array before resetting the count.

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs [1271-1281]

 finally
 {
     // Reset init data.
-    s_GlobalState.initPairWithDevicesCount = 0;
     if (s_GlobalState.initPairWithDevices != null)
         Array.Clear(s_GlobalState.initPairWithDevices, 0, s_GlobalState.initPairWithDevicesCount);
+    s_GlobalState.initPairWithDevicesCount = 0;
     s_GlobalState.initControlScheme = null;
     s_GlobalState.initPlayerIndex = -1;
     s_GlobalState.initSplitScreenIndex = -1;
     s_GlobalState.destroyIfDeviceSetupUnsuccessful = false;
 }
Suggestion importance[1-10]: 9

__

Why: The current code resets initPairWithDevicesCount to 0 before using it as the length argument for Array.Clear. This causes Array.Clear to do nothing, leaving references to InputDevice objects in the static array and potentially causing memory leaks.

High
Initialize touch state for Editor usage

s_GlobalState is left uninitialized (defaulting to zero history length) when the
Editor starts or after a domain reload, as InitializeGlobalTouchState only runs on
Play Mode entry. Restore the inline initialization to ensure s_GlobalState is valid
for Editor usage before Play Mode.

Packages/com.unity.inputsystem/InputSystem/Plugins/EnhancedTouch/Touch.cs [722-729]

-internal static GlobalState s_GlobalState;
+internal static GlobalState s_GlobalState = new GlobalState { historyLengthPerFinger = 64 };
 
 [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
 private static void InitializeGlobalTouchState()
 {
     // Touch GlobalState doesn't require Dispose operations
     s_GlobalState = new GlobalState { historyLengthPerFinger = 64 };
 }
Suggestion importance[1-10]: 7

__

Why: RuntimeInitializeOnLoadMethod only runs when entering Play Mode. Without inline initialization, s_GlobalState will be zero-initialized (default struct) in the Editor after a domain reload, which may cause issues if EnhancedTouch is used in Edit Mode (e.g., expecting historyLengthPerFinger to be 64).

Medium
Reset global state in Instantiate startup

If an exception occurs during the setup phase (e.g. inside
ArrayHelpers.AppendWithCapacity), initPairWithDevicesCount is not reset, leading to
dirty state for subsequent calls. Explicitly reset initPairWithDevicesCount to 0 at
the start of Instantiate to ensure a clean state.

Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/PlayerInput.cs [1208-1212]

 public static PlayerInput Instantiate(GameObject prefab, int playerIndex = -1, string controlScheme = null, int splitScreenIndex = -1, InputDevice pairWithDevice = null)
 {
     if (prefab == null)
         throw new ArgumentNullException(nameof(prefab));
 
     // Set initialization data.
+    s_GlobalState.initPairWithDevicesCount = 0;
     s_GlobalState.initPlayerIndex = playerIndex;
     s_GlobalState.initSplitScreenIndex = splitScreenIndex;
Suggestion importance[1-10]: 6

__

Why: Explicitly resetting initPairWithDevicesCount ensures that if a previous call to Instantiate failed (e.g., throwing an exception before DoInstantiate cleanup), the static state is reset, preventing stale devices from affecting subsequent instantiations.

Low
General
Prevent lazy instantiation during serialization

Accessing InputSystem.manager and InputSystem.remoting properties will force their
creation if they are null. It is better to check the internal fields s_Manager and
s_Remote to avoid creating empty systems just to serialize their state.

Packages/com.unity.inputsystem/InputSystem/InputSystemStateManager.cs [82-91]

 public void OnBeforeSerialize()
 {
     // Save current system state.
-    systemState.manager = InputSystem.manager;
-    systemState.remote = InputSystem.remoting;
+    if (InputSystem.s_Manager != null)
+    {
+        systemState.manager = InputSystem.s_Manager;
+        systemState.managerState = InputSystem.s_Manager.SaveState();
+    }
+
+    if (InputSystem.s_Remote != null)
+    {
+        systemState.remote = InputSystem.s_Remote;
+        systemState.remotingState = InputSystem.s_Remote.SaveState();
+    }
+    
     systemState.remoteConnection = InputSystem.remoteConnection;
-    systemState.managerState = InputSystem.manager.SaveState();
-    systemState.remotingState = InputSystem.remoting.SaveState();
     systemState.userSettings = InputEditorUserSettings.s_Settings;
 }
Suggestion importance[1-10]: 9

__

Why: Using properties InputSystem.manager and InputSystem.remoting in OnBeforeSerialize will lazily instantiate these systems if they don't exist. This defeats the purpose of serializing state during a domain reload, as it might create and save empty systems instead of preserving the actual (possibly null) state.

High
Avoid creating manager just to dispose it

Accessing InputSystem.manager triggers the creation of a new InputManager if one
does not exist. Using Dispose() on a freshly created manager is unnecessary and
wasteful. Use the backing field s_Manager with a null check instead.

Packages/com.unity.inputsystem/InputSystem/InputSystemTestHooks.cs [64-71]

 internal static void TestHook_DestroyAndReset()
 {
     // NOTE: Does not destroy InputSystemObject. We want to destroy input system
     //       state repeatedly during tests but we want to not create InputSystemObject
     //       over and over.
-    InputSystem.manager.Dispose();
+    s_Manager?.Dispose();
     if (InputSystem.s_RemoteConnection != null)
         Object.DestroyImmediate(InputSystem.s_RemoteConnection);
Suggestion importance[1-10]: 8

__

Why: Accessing InputSystem.manager triggers the creation of the manager if it is null. In a cleanup method like TestHook_DestroyAndReset, creating a manager just to dispose of it is wasteful and potentially incorrect. Using the backing field s_Manager prevents this side effect.

Medium
  • More suggestions

🤖 Helpful? Please react with 👍/👎 | Questions❓Please reach out in Slack #ask-u-pr

@codecov-github-com
Copy link

codecov-github-com bot commented Feb 18, 2026

Codecov Report

Attention: Patch coverage is 88.77888% with 68 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/com.unity.inputsystem/InputSystem/InputSystem.cs 78.20% 17 Missing ⚠️
Assets/Tests/InputSystem/CoreTests_Actions.cs 38.88% 11 Missing ⚠️
...utSystem/Actions/InputActionRebindingExtensions.cs 83.78% 6 Missing ⚠️
...InputSystem/Editor/Debugger/InputDebuggerWindow.cs 0.00% 6 Missing ⚠️
.../com.unity.inputsystem/InputSystem/InputManager.cs 95.09% 5 Missing ⚠️
...tsystem/Tests/TestFixture/InputTestStateManager.cs 90.90% 5 Missing ⚠️
...nputsystem/InputSystem/Actions/InputActionState.cs 84.61% 2 Missing ⚠️
...ystem/Editor/Debugger/InputDeviceDebuggerWindow.cs 0.00% 2 Missing ⚠️
...utSystem/Plugins/PlayerInput/PlayerInputManager.cs 71.42% 2 Missing ⚠️
....unity.inputsystem/InputSystem/State/InputState.cs 77.77% 2 Missing ⚠️
... and 10 more
@@             Coverage Diff             @@
##           develop    #2343      +/-   ##
===========================================
+ Coverage    77.95%   77.99%   +0.03%     
===========================================
  Files          476      480       +4     
  Lines        97453    97513      +60     
===========================================
+ Hits         75971    76052      +81     
+ Misses       21482    21461      -21     
Flag Coverage Δ
inputsystem_MacOS_2022.3 5.52% <2.55%> (-0.02%) ⬇️
inputsystem_MacOS_2022.3_project 75.53% <88.51%> (+0.06%) ⬆️
inputsystem_MacOS_6000.0 5.29% <1.96%> (-0.03%) ⬇️
inputsystem_MacOS_6000.0_project 77.42% <88.77%> (+0.06%) ⬆️
inputsystem_MacOS_6000.3 5.29% <1.96%> (-0.03%) ⬇️
inputsystem_MacOS_6000.3_project 77.42% <88.77%> (+0.06%) ⬆️
inputsystem_MacOS_6000.4 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_MacOS_6000.4_project 77.43% <88.77%> (+0.06%) ⬆️
inputsystem_MacOS_6000.5 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_MacOS_6000.5_project 77.43% <88.77%> (+0.06%) ⬆️
inputsystem_Ubuntu_2022.3 5.52% <2.55%> (-0.02%) ⬇️
inputsystem_Ubuntu_2022.3_project 75.33% <88.51%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.0 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.0_project 77.22% <88.77%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.3 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.3_project 77.23% <88.77%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.4 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.4_project 77.23% <88.77%> (+0.06%) ⬆️
inputsystem_Ubuntu_6000.5 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Ubuntu_6000.5_project 77.24% <88.77%> (+0.06%) ⬆️
inputsystem_Windows_2022.3 5.52% <2.55%> (-0.02%) ⬇️
inputsystem_Windows_2022.3_project 75.66% <88.51%> (+0.06%) ⬆️
inputsystem_Windows_6000.0 5.29% <1.96%> (-0.03%) ⬇️
inputsystem_Windows_6000.0_project 77.55% <88.77%> (+0.05%) ⬆️
inputsystem_Windows_6000.3 5.29% <1.96%> (-0.03%) ⬇️
inputsystem_Windows_6000.3_project 77.55% <88.77%> (+0.06%) ⬆️
inputsystem_Windows_6000.4 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Windows_6000.4_project 77.55% <88.77%> (+0.06%) ⬆️
inputsystem_Windows_6000.5 5.30% <1.96%> (-0.03%) ⬇️
inputsystem_Windows_6000.5_project 77.55% <88.77%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
Assets/Tests/InputSystem/CoreTests_Analytics.cs 99.36% <ø> (-0.01%) ⬇️
Assets/Tests/InputSystem/CoreTests_Devices.cs 98.23% <100.00%> (ø)
Assets/Tests/InputSystem/CoreTests_Editor.cs 97.95% <100.00%> (ø)
Assets/Tests/InputSystem/CoreTests_Events.cs 98.49% <100.00%> (ø)
Assets/Tests/InputSystem/CoreTests_Remoting.cs 92.70% <100.00%> (-0.15%) ⬇️
Assets/Tests/InputSystem/CoreTests_State.cs 96.42% <100.00%> (ø)
Assets/Tests/InputSystem/Plugins/HIDTests.cs 97.94% <100.00%> (ø)
Assets/Tests/InputSystem/Plugins/SteamTests.cs 89.90% <100.00%> (-0.17%) ⬇️
...nputsystem/InputSystem/Actions/InputActionAsset.cs 85.83% <100.00%> (ø)
....inputsystem/InputSystem/Actions/InputActionMap.cs 94.76% <100.00%> (-0.03%) ⬇️
... and 44 more

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@u-pr
Copy link
Contributor

u-pr bot commented Feb 18, 2026

Persistent review updated to latest commit 55baff2

@u-pr
Copy link
Contributor

u-pr bot commented Feb 18, 2026

Persistent review updated to latest commit 1415877

@u-pr
Copy link
Contributor

u-pr bot commented Feb 18, 2026

Persistent review updated to latest commit 877bb11

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.

3 participants

Comments