Skip to content

Commit 1655b7f

Browse files
committed
always duplicate PlayerInput action assets and removed redundant pjwd actions enabling calls
1 parent ae27089 commit 1655b7f

File tree

3 files changed

+14
-38
lines changed

3 files changed

+14
-38
lines changed

Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ public void PlayerInput_CanUseSameActionsForUIInputModule()
149149
eventSystemGO.SetActive(true);
150150
playerGO.SetActive(true);
151151

152-
Assert.That(actions.FindActionMap("Gameplay").enabled, Is.True);
153-
Assert.That(actions.FindActionMap("UI").enabled, Is.True);
154-
Assert.That(actions["UI/Navigate"].controls, Is.Empty);
155-
Assert.That(actions["UI/Point"].controls, Is.EquivalentTo(new[] { mouse.position }));
156-
Assert.That(actions["UI/Click"].controls, Is.EquivalentTo(new[] { mouse.leftButton }));
152+
Assert.That(player.actions.FindActionMap("Gameplay").enabled, Is.True);
153+
Assert.That(uiModule.actionsAsset.FindActionMap("UI").enabled, Is.True);
154+
Assert.That(uiModule.actionsAsset["UI/Navigate"].controls, Is.Empty);
155+
Assert.That(uiModule.actionsAsset["UI/Point"].controls, Is.EquivalentTo(new[] { mouse.position }));
156+
Assert.That(uiModule.actionsAsset["UI/Click"].controls, Is.EquivalentTo(new[] { mouse.leftButton }));
157157
}
158158

159159
[Test]

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3609,12 +3609,6 @@ internal static void InitializeInEditor(IInputRuntime runtime = null)
36093609
// this would cancel the import of large assets that are dependent on the InputSystem package and import it as a dependency.
36103610
EditorApplication.delayCall += ShowRestartWarning;
36113611

3612-
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
3613-
// Make sure project wide input actions are enabled.
3614-
// Note that this will always fail if entering play-mode within editor since not yet in play-mode.
3615-
EnableActions();
3616-
#endif
3617-
36183612
RunInitialUpdate();
36193613

36203614
k_InputInitializeInEditorMarker.End();
@@ -3657,9 +3651,6 @@ internal static void OnPlayModeChange(PlayModeStateChange change)
36573651
case PlayModeStateChange.EnteredPlayMode:
36583652
s_SystemObject.enterPlayModeTime = InputRuntime.s_Instance.currentTime;
36593653
s_Manager.SyncAllDevicesAfterEnteringPlayMode();
3660-
#if UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
3661-
EnableActions();
3662-
#endif // UNITY_INPUT_SYSTEM_PROJECT_WIDE_ACTIONS
36633654
break;
36643655

36653656
case PlayModeStateChange.ExitingPlayMode:

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

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ public void ActivateInput()
956956

957957
// reset state to default, only one action map is enabled at the initial state
958958
// Project wide actions may have enabled action maps
959-
if (m_Actions != null)
959+
if (m_Actions)
960960
m_Actions.Disable();
961961

962962
// If we have no current action map but there's a default
@@ -1373,18 +1373,14 @@ private void InitializeActions()
13731373
if (m_Actions == null)
13741374
return;
13751375

1376-
// don't use project wide action asset for player input, but duplicate it
1377-
if (InputSystem.actions != null && InputSystem.actions.Equals(m_Actions))
1378-
DuplicateActionsForPlayer();
1379-
1380-
// Check if we need to duplicate our actions by looking at all other players. If any
1381-
// has the same actions, duplicate.
1382-
for (var i = 0; i < s_AllActivePlayersCount; ++i)
1383-
if (s_AllActivePlayers[i].m_Actions == m_Actions && s_AllActivePlayers[i] != this)
1384-
{
1385-
DuplicateActionsForPlayer();
1386-
break;
1387-
}
1376+
// duplicate action asset to not operate on the original (as it might be used outside - eg project wide action asset or UIInputModule)
1377+
var oldActions = m_Actions;
1378+
m_Actions = Instantiate(m_Actions);
1379+
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
1380+
{
1381+
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
1382+
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
1383+
}
13881384

13891385
#if UNITY_INPUT_SYSTEM_ENABLE_UI
13901386
if (uiInputModule != null)
@@ -1432,17 +1428,6 @@ private void InitializeActions()
14321428
m_ActionsInitialized = true;
14331429
}
14341430

1435-
private void DuplicateActionsForPlayer()
1436-
{
1437-
var oldActions = m_Actions;
1438-
m_Actions = Instantiate(m_Actions);
1439-
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
1440-
{
1441-
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
1442-
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
1443-
}
1444-
}
1445-
14461431
private void UninitializeActions()
14471432
{
14481433
if (!m_ActionsInitialized)

0 commit comments

Comments
 (0)