Skip to content

Commit 2281ca6

Browse files
committed
adjusted test, assets distinct for every copy now (consistently for all players) fixed initialisation
1 parent a441d03 commit 2281ca6

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

Assets/Tests/InputSystem/Plugins/PlayerInputTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2427,13 +2427,13 @@ public void PlayerInput_DelegatesAreUpdate_WhenActionMapAddedAfterAssignment()
24272427
// Disable the asset while adding another action map to it as none
24282428
// of the actions in the asset can be enabled during modification
24292429
//
2430-
actionAsset.Disable();
2430+
playerInput.actions.Disable();
24312431
var keyboard = InputSystem.AddDevice<Keyboard>();
2432-
var newActionMap = actionAsset.AddActionMap("NewMap");
2432+
var newActionMap = playerInput.actions.AddActionMap("NewMap");
24332433
var newAction = newActionMap.AddAction("NewAction");
24342434
newAction.AddBinding("<Keyboard>/k", groups: "Keyboard");
2435-
actionAsset.AddControlScheme("Keyboard").WithRequiredDevice<Keyboard>();
2436-
actionAsset.Enable();
2435+
playerInput.actions.AddControlScheme("Keyboard").WithRequiredDevice<Keyboard>();
2436+
playerInput.actions.Enable();
24372437

24382438
playerInput.currentActionMap = newActionMap;
24392439
playerInput.ActivateInput();

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,7 @@ public InputActionAsset actions
346346

347347
if (m_Enabled)
348348
{
349-
ClearCaches();
350-
AssignUserAndDevices();
351-
InitializeActions();
352-
if (m_InputActive)
353-
ActivateInput();
349+
Init();
354350
}
355351
}
356352
}
@@ -1363,16 +1359,16 @@ private void InitializeActions()
13631359

13641360
// duplicate action asset to not operate on the original(as it might be used outside - eg project wide action asset or UIInputModule)
13651361
var oldActions = m_Actions;
1366-
m_Actions = Instantiate(m_Actions);
1362+
var newActions = Instantiate(m_Actions);
13671363
for (var actionMap = 0; actionMap < oldActions.actionMaps.Count; actionMap++)
13681364
{
13691365
for (var binding = 0; binding < oldActions.actionMaps[actionMap].bindings.Count; binding++)
1370-
m_Actions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
1366+
newActions.actionMaps[actionMap].ApplyBindingOverride(binding, oldActions.actionMaps[actionMap].bindings[binding]);
13711367
}
1372-
1373-
// reset state to default, only one action map is enabled at the initial state
1374-
// Project wide actions may have enabled action maps
1375-
m_Actions.Disable();
1368+
//reset state to default, only one action map is enabled at the initial state
1369+
//Project wide actions may have enabled action maps
1370+
newActions.Disable();
1371+
m_Actions = newActions;
13761372

13771373
#if UNITY_INPUT_SYSTEM_ENABLE_UI
13781374
if (uiInputModule != null)
@@ -1792,15 +1788,10 @@ void Reset()
17921788
private void OnEnable()
17931789
{
17941790
m_Enabled = true;
1795-
17961791
using (InputActionRebindingExtensions.DeferBindingResolution())
17971792
{
17981793
AssignPlayerIndex();
1799-
InitializeActions();
1800-
AssignUserAndDevices();
1801-
ActivateInput();
18021794
}
1803-
18041795
// Split-screen index defaults to player index.
18051796
if (s_InitSplitScreenIndex >= 0)
18061797
m_SplitScreenIndex = splitScreenIndex;
@@ -1813,6 +1804,9 @@ private void OnEnable()
18131804
for (var j = i; j > 0 && s_AllActivePlayers[j - 1].playerIndex > s_AllActivePlayers[j].playerIndex; --j)
18141805
s_AllActivePlayers.SwapElements(j, j - 1);
18151806

1807+
1808+
Init();
1809+
18161810
// If it's the first player, hook into user change notifications.
18171811
if (s_AllActivePlayersCount == 1)
18181812
{
@@ -1844,6 +1838,16 @@ private void OnEnable()
18441838
PlayerInputManager.instance?.NotifyPlayerJoined(this);
18451839
}
18461840

1841+
private void Init()
1842+
{
1843+
using (InputActionRebindingExtensions.DeferBindingResolution())
1844+
{
1845+
InitializeActions();
1846+
AssignUserAndDevices();
1847+
ActivateInput();
1848+
}
1849+
}
1850+
18471851
private void StartListeningForUnpairedDeviceActivity()
18481852
{
18491853
if (m_OnUnpairedDeviceUsedHooked)

0 commit comments

Comments
 (0)