Skip to content

Commit 086bb2f

Browse files
committed
[Input System] PlayerInput component - ensure any added action map delegates are updated on ActivateInput() (case ISXB-711)
If action maps are added to an asset *after* the asset has been assigned to the PlayerInput component then the delegates need to be updated. Before this change no On<XXX> callbacks were created for the added maps leading to input loss. Adding this sync in the ActivateInput() seems like the best compromise.
1 parent c9d686d commit 086bb2f

File tree

1 file changed

+20
-0
lines changed
  • Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput

1 file changed

+20
-0
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,8 @@ public TDevice GetDevice<TDevice>()
950950
/// </example>
951951
public void ActivateInput()
952952
{
953+
UpdateDelegates();
954+
953955
m_InputActive = true;
954956

955957
// If we have no current action map but there's a default
@@ -960,6 +962,22 @@ public void ActivateInput()
960962
m_CurrentActionMap?.Enable();
961963
}
962964

965+
// Users can add and remove actions maps *after* assigning an InputActionAsset to the PlayerInput component.
966+
// This ensures "actionTriggered" delegates are assigned for new maps (case isxb-711)
967+
//
968+
private int m_MapCount = 0;
969+
private void UpdateDelegates()
970+
{
971+
if (m_Actions == null)
972+
return;
973+
if (m_MapCount != m_Actions.actionMaps.Count)
974+
{
975+
InstallOnActionTriggeredHook();
976+
CacheMessageNames();
977+
m_MapCount = m_Actions.actionMaps.Count;
978+
}
979+
}
980+
963981
/// <summary>
964982
/// Disable input on the player, by disabling the current action map
965983
/// </summary>
@@ -1515,6 +1533,8 @@ private void CacheMessageNames()
15151533

15161534
private void ClearCaches()
15171535
{
1536+
if (m_ActionMessageNames != null)
1537+
m_ActionMessageNames.Clear();
15181538
}
15191539

15201540
/// <summary>

0 commit comments

Comments
 (0)