Repository navigation
FIX: [Port] [UUM-151403] [Input System] Fixed actions enabled during startup being disabled #2500
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
josepmariapujol-unity
merged 2 commits into
develop
from
input/uum-151403-actions-enabled-during-startup-disabled
Oct 29, 2026
+220
−10
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
173 changes: 173 additions & 0 deletions
173
Assets/Tests/InputSystem.Editor/InputActionStatePlayModeTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| using System; | ||
| using System.Collections; | ||
| using NUnit.Framework; | ||
| using UnityEditor; | ||
| using UnityEngine; | ||
| using UnityEngine.InputSystem; | ||
| using UnityEngine.TestTools; | ||
| using Object = UnityEngine.Object; | ||
|
|
||
| // Enters real play mode so that the engine runs every RuntimeInitializeOnLoadMethod in its own order. | ||
| // This deliberately does not derive from InputTestFixture, which replaces the runtime and global state. | ||
| internal class InputActionStatePlayModeTests | ||
| { | ||
| const string k_TestCategory = "Editor"; | ||
| const string k_ArmedKey = "InputSystem.Tests.InputActionStatePlayModeTests.Armed"; | ||
| const string k_EnabledAfterSceneLoadKey = "InputSystem.Tests.InputActionStatePlayModeTests.EnabledAfterSceneLoad"; | ||
| const string k_SavedOptionsKey = "InputSystem.Tests.InputActionStatePlayModeTests.SavedOptions"; | ||
| const string k_SavedOptionsEnabledKey = "InputSystem.Tests.InputActionStatePlayModeTests.SavedOptionsEnabled"; | ||
|
|
||
| static readonly bool[] k_DisableDomainReloadValues = { false, true }; | ||
|
|
||
| static InputAction s_EarlyAction; | ||
|
|
||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
| static void EnableActionBeforeSceneLoad() | ||
| { | ||
| if (!SessionState.GetBool(k_ArmedKey, false)) | ||
| return; | ||
|
|
||
| s_EarlyAction = new InputAction(binding: "<Keyboard>/space"); | ||
| s_EarlyAction.Enable(); | ||
| } | ||
|
|
||
| [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)] | ||
| static void RecordActionAfterSceneLoad() | ||
| { | ||
| if (!SessionState.GetBool(k_ArmedKey, false)) | ||
| return; | ||
|
|
||
| SessionState.SetBool(k_EnabledAfterSceneLoadKey, s_EarlyAction != null && s_EarlyAction.enabled); | ||
| } | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| // Each domain reload during the test runs SetUp again, so only record the options once. | ||
| if (SessionState.GetInt(k_SavedOptionsKey, -1) != -1) | ||
| return; | ||
|
|
||
| // Unity 6000.0 reports no options while they are disabled, so enable them to read the stored ones. | ||
| var optionsEnabled = EditorSettings.enterPlayModeOptionsEnabled; | ||
| EditorSettings.enterPlayModeOptionsEnabled = true; | ||
| SessionState.SetInt(k_SavedOptionsKey, (int)EditorSettings.enterPlayModeOptions); | ||
| SessionState.SetBool(k_SavedOptionsEnabledKey, optionsEnabled); | ||
| EditorSettings.enterPlayModeOptionsEnabled = optionsEnabled; | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| if (Application.isPlaying) | ||
| return; | ||
|
|
||
| EditorSettings.enterPlayModeOptionsEnabled = true; | ||
| EditorSettings.enterPlayModeOptions = (EnterPlayModeOptions)SessionState.GetInt(k_SavedOptionsKey, 0); | ||
| EditorSettings.enterPlayModeOptionsEnabled = SessionState.GetBool(k_SavedOptionsEnabledKey, false); | ||
|
|
||
| // Entering play mode saves the modified settings to disk, so save the restored ones too. | ||
| AssetDatabase.SaveAssets(); | ||
| SessionState.EraseInt(k_SavedOptionsKey); | ||
| SessionState.EraseBool(k_SavedOptionsEnabledKey); | ||
| SessionState.EraseBool(k_ArmedKey); | ||
| SessionState.EraseBool(k_EnabledAfterSceneLoadKey); | ||
|
|
||
| s_EarlyAction?.Dispose(); | ||
| s_EarlyAction = null; | ||
| } | ||
|
|
||
| static void SetDomainReloadDisabled(bool disabled) | ||
| { | ||
| // Unity 6000.0 ignores enterPlayModeOptions unless the options are enabled. | ||
| EditorSettings.enterPlayModeOptionsEnabled = true; | ||
| EditorSettings.enterPlayModeOptions = disabled | ||
| ? EnterPlayModeOptions.DisableDomainReload | EnterPlayModeOptions.DisableSceneReload | ||
| : EnterPlayModeOptions.None; | ||
| } | ||
|
|
||
| static bool HasOnActionChangeCallback(Action<object, InputActionChange> callback) | ||
| { | ||
| var callbacks = InputActionState.s_GlobalState.onActionChange; | ||
| for (var i = 0; i < callbacks.length; ++i) | ||
| { | ||
| if (callbacks[i] == callback) | ||
| return true; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| [UnityTest] | ||
| [Category(k_TestCategory)] | ||
| [Description("https://jira.unity3d.com/browse/UUM-151403")] | ||
| public IEnumerator Actions_EnabledBeforeSceneLoad_StayEnabled_WhenEnteringPlayMode( | ||
| [ValueSource(nameof(k_DisableDomainReloadValues))] bool disableDomainReload) | ||
| { | ||
| SetDomainReloadDisabled(disableDomainReload); | ||
| SessionState.SetBool(k_ArmedKey, true); | ||
|
|
||
| yield return new EnterPlayMode(); | ||
|
|
||
| SessionState.SetBool(k_ArmedKey, false); | ||
| Assert.That(SessionState.GetBool(k_EnabledAfterSceneLoadKey, false), Is.True); | ||
|
|
||
| yield return new ExitPlayMode(); | ||
|
|
||
| // Without a domain reload the action object survives, but exiting play mode must still clean up its state. | ||
| if (disableDomainReload) | ||
| Assert.That(s_EarlyAction.enabled, Is.False); | ||
| } | ||
|
|
||
| [UnityTest] | ||
| [Category(k_TestCategory)] | ||
| [Description("https://jira.unity3d.com/browse/UUM-151403")] | ||
| public IEnumerator Actions_OnActionChangeCallbacksAddedInPlayMode_AreRemovedOnExit_WhenDomainReloadIsDisabled() | ||
| { | ||
| SetDomainReloadDisabled(true); | ||
|
|
||
| Action<object, InputActionChange> editModeCallback = (obj, change) => {}; | ||
| Action<object, InputActionChange> playModeCallback = (obj, change) => {}; | ||
| var survivingListener = ScriptableObject.CreateInstance<ActionChangeListener>(); | ||
| survivingListener.hideFlags = HideFlags.HideAndDontSave; | ||
| var destroyedListener = ScriptableObject.CreateInstance<ActionChangeListener>(); | ||
| destroyedListener.hideFlags = HideFlags.HideAndDontSave; | ||
| Action<object, InputActionChange> survivingListenerCallback = survivingListener.OnActionChange; | ||
| Action<object, InputActionChange> destroyedListenerCallback = destroyedListener.OnActionChange; | ||
| InputSystem.onActionChange += editModeCallback; | ||
| try | ||
| { | ||
| yield return new EnterPlayMode(); | ||
|
|
||
| Assert.That(HasOnActionChangeCallback(editModeCallback), Is.True); | ||
| InputSystem.onActionChange += playModeCallback; | ||
|
|
||
| // Like an editor window opened during play mode, which stays open after it. | ||
| InputSystem.onActionChange += survivingListenerCallback; | ||
|
|
||
| // Like a component of a play mode GameObject, which is destroyed on exit. | ||
| InputSystem.onActionChange += destroyedListenerCallback; | ||
| Object.DestroyImmediate(destroyedListener); | ||
|
|
||
| yield return new ExitPlayMode(); | ||
|
|
||
| Assert.That(HasOnActionChangeCallback(editModeCallback), Is.True); | ||
| Assert.That(HasOnActionChangeCallback(playModeCallback), Is.False); | ||
| Assert.That(HasOnActionChangeCallback(survivingListenerCallback), Is.True); | ||
| Assert.That(HasOnActionChangeCallback(destroyedListenerCallback), Is.False); | ||
| } | ||
| finally | ||
| { | ||
| InputSystem.onActionChange -= editModeCallback; | ||
| InputSystem.onActionChange -= playModeCallback; | ||
| InputSystem.onActionChange -= survivingListenerCallback; | ||
| InputSystem.onActionChange -= destroyedListenerCallback; | ||
| Object.DestroyImmediate(survivingListener); | ||
| } | ||
| } | ||
|
|
||
| class ActionChangeListener : ScriptableObject | ||
| { | ||
| public void OnActionChange(object actionOrMap, InputActionChange change) | ||
| { | ||
| } | ||
| } | ||
| } | ||
2 changes: 2 additions & 0 deletions
2
Assets/Tests/InputSystem.Editor/InputActionStatePlayModeTests.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
disableDomainReload=truecase still reloads the domain with the checked-in Unity 6000.0 settings, leavings_EarlyActionnull afterExitPlayMode. The project setsenterPlayModeOptionsEnabledto false, andSetDomainReloadDisabledonly changesenterPlayModeOptions. Unity 6000.0 ignores those options untilenterPlayModeOptionsEnabledis enabled. The assertion ons_EarlyAction.enabledthen throws, and the callback test also runs with the wrong reload configuration. SaveenterPlayModeOptionsEnabledalongside the existing options. Enable it when configuring the tests. Restore it inTearDown.🤖 Helpful? 👍/👎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ae4c058, the tests now enable the enter play mode options and save and restore the enabled flag too.