Skip to content

Commit adb79c6

Browse files
committed
Only EnableActions() on InitializeInEditor()
This reverts added changes and makes it consistent with InitializeInPlayerBehavior.
1 parent f7b6585 commit adb79c6

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

Assets/Tests/InputSystem/CoreTests_ProjectWideActions.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using UnityEngine.InputSystem;
66
using UnityEngine.TestTools;
77
using UnityEngine;
8+
using System.Collections;
89

910
#if UNITY_EDITOR
1011
using System.IO;
@@ -143,11 +144,11 @@ public void ProjectWideActions_AppearInEnabledActions()
143144

144145
[Category(TestCategory)]
145146
[Test]
146-
[TestCase("Player", true, Description = "PlayerInput using project-wide actions has the default action map set " +
147+
[TestCase("Player", true, Description = "PlayerInput using project-wide actions can have default action map set " +
147148
"enabled, and all others disabled.")]
148149
[TestCase(null, false, Description = "PlayerInput using project wide actions has all action maps of project-wide " +
149150
"actions disabled, if there is no default action map assigned.")]
150-
public void ProjectWideActions_AreDisabledWithPlayerInput(string actionMapName, bool expectedResult)
151+
public void ProjectWideActions_CanEnableCurrentActionMapOfPlayerInput(string actionMapName, bool expectedResult)
151152
{
152153
var keyboard = InputSystem.AddDevice<Keyboard>();
153154
var go = new GameObject("PlayerInput");
@@ -159,29 +160,40 @@ public void ProjectWideActions_AreDisabledWithPlayerInput(string actionMapName,
159160
// will be called.
160161
playerInput.defaultActionMap = actionMapName;
161162

162-
#if UNITY_EDITOR
163+
// PWA actions assigned to playerInput start enabled
164+
Assert.That(playerInput.actions.enabled, Is.True);
165+
Assert.That(ReferenceEquals(playerInput.actions, InputSystem.actions));
166+
167+
#if UNITY_EDITOR
163168
InputSystem.OnPlayModeChange(PlayModeStateChange.ExitingEditMode);
164-
#endif
169+
#endif
165170

166171
// This makes sure to call PlayerInput.OnEnable()
167172
go.SetActive(true);
168173

169-
Assert.That(ReferenceEquals(playerInput.actions, InputSystem.actions));
174+
// This mimics usings to disabling actions on Start/Awake.
175+
InputSystem.actions.Disable();
176+
177+
if (!string.IsNullOrEmpty(actionMapName))
178+
playerInput.SwitchCurrentActionMap("Player");
179+
170180
Assert.That(playerInput.actions.enabled, Is.EqualTo(expectedResult));
171181

172-
#if UNITY_EDITOR
173-
// This mimics the behavior of entering play-mode, which will check if InputSystem.EnableActions() should
174-
// be called.
182+
// We do this on the editor to make sure project-wide actions maintain the enabled state
183+
// after entering PlayMode.
184+
#if UNITY_EDITOR
175185
InputSystem.OnPlayModeChange(PlayModeStateChange.EnteredPlayMode);
176-
#endif
186+
Assert.That(playerInput.actions.enabled, Is.EqualTo(expectedResult));
187+
#endif
177188

178-
if (actionMapName != null)
189+
if (!string.IsNullOrEmpty(actionMapName))
179190
Assert.That(playerInput.currentActionMap.enabled, Is.EqualTo(expectedResult));
180191

192+
// Check state of all action maps in the asset
181193
Assert.That(InputSystem.actions.FindActionMap("Player").enabled, Is.EqualTo(expectedResult));
182194
Assert.That(InputSystem.actions.FindActionMap("UI").enabled, Is.False);
183195

184-
//NOTE: Asset actions will be considered enabled even if a single action map is enabled
196+
//NOTE: Asset actions are considered enabled even if a single action map is enabled
185197
Assert.That(playerInput.actions.enabled, Is.EqualTo(expectedResult));
186198
}
187199
}

Packages/com.unity.inputsystem/InputSystem/InputSystem.cs

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3038,19 +3038,6 @@ private static void EnableActions()
30383038
actions.Enable();
30393039
}
30403040

3041-
/// <summary>
3042-
/// Determines whether project-wide actions are automatically enabled after entering Play Mode.
3043-
/// </summary>
3044-
/// <remarks>
3045-
/// This property is set to <c>true</c> by default.
3046-
/// </remarks>
3047-
internal static bool m_EnableActionsAfterEnterPlayMode = true;
3048-
3049-
internal static void AllowEnableActionsAfterEnterPlayMode(bool enabled)
3050-
{
3051-
m_EnableActionsAfterEnterPlayMode = enabled;
3052-
}
3053-
30543041
private static void DisableActions(bool triggerSetupChanged = false)
30553042
{
30563043
// Make sure project wide input actions are disabled
@@ -3663,14 +3650,7 @@ internal static void OnPlayModeChange(PlayModeStateChange change)
36633650
case PlayModeStateChange.EnteredPlayMode:
36643651
s_SystemObject.enterPlayModeTime = InputRuntime.s_Instance.currentTime;
36653652
s_Manager.SyncAllDevicesAfterEnteringPlayMode();
3666-
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
3667-
// Check if project-wide actions should be enabled after entering PlayMode.
3668-
// In some cases, like using project-wide actions in PlayerInput, we don't want actions to be
3669-
// enabled when entering PlayMode so that PlayerInput is able to enable the default action map.
3670-
if (m_EnableActionsAfterEnterPlayMode)
3671-
EnableActions();
36723653

3673-
#endif // UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
36743654
break;
36753655

36763656
case PlayModeStateChange.ExitingPlayMode:
@@ -3928,8 +3908,8 @@ private static void Reset(bool enableRemoting = false, IInputRuntime runtime = n
39283908
InputUser.ResetGlobals();
39293909
EnhancedTouchSupport.Reset();
39303910

3931-
// This is the point where we initialise project-wide actions for the Editor, Editor Tests and Player Tests.
3932-
// Note this is too early for editor ! actions is not setup yet.
3911+
// // This is the point where we initialise project-wide actions for the Editor, Editor Tests and Player Tests.
3912+
// // Note this is too early for editor ! actions is not setup yet.
39333913
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
39343914
EnableActions();
39353915
#endif

0 commit comments

Comments
 (0)