Skip to content

Commit 4db0e76

Browse files
authored
FIX: Fixed a performance issue with many objects using multiple action maps [ISXB-573] (#1951)
FIX: Fixed a performance issue with many objects using multiple action maps [ISXB-573](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-573).
1 parent 6037d4d commit 4db0e76

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ however, it has to be formatted properly to pass verification tests.
2525
- Fixed an issue where adding a `OnScreenButton` or `OnScreenStick` to a regular GameObject would lead to exception in editor.
2626
- Fixed an issue where adding a `OnScreenStick` to a regular GameObject and entering play-mode would lead to exceptions being generated.
2727
- Fixed InputActionReference issues when domain reloads are disabled [ISXB-601](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-601), [ISXB-718](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-718), [ISXB-900](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-900)
28+
- Fixed a performance issue with many objects using multiple action maps [ISXB-573](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-573).
2829

2930
### Added
3031
- Added additional device information when logging the error due to exceeding the maximum number of events processed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ public event Action<InputAction.CallbackContext> actionTriggered
318318
/// </summary>
319319
public InputActionMap()
320320
{
321+
s_NeedToResolveBindings = true;
321322
}
322323

323324
/// <summary>
@@ -810,6 +811,7 @@ private enum Flags
810811
}
811812

812813
internal static int s_DeferBindingResolution;
814+
internal static bool s_NeedToResolveBindings;
813815

814816
internal struct DeviceArray
815817
{
@@ -1193,6 +1195,9 @@ internal bool LazyResolveBindings(bool fullResolve)
11931195
m_ControlsForEachAction = null;
11941196
controlsForEachActionInitialized = false;
11951197

1198+
// Indicate that there is at least one action map that has a change
1199+
s_NeedToResolveBindings = true;
1200+
11961201
// If we haven't had to resolve bindings yet, we can wait until when we
11971202
// actually have to.
11981203
if (m_State == null)
@@ -1982,6 +1987,9 @@ public void OnBeforeSerialize()
19821987
/// </summary>
19831988
public void OnAfterDeserialize()
19841989
{
1990+
// Indicate that there is at least one action map that has a change
1991+
s_NeedToResolveBindings = true;
1992+
19851993
m_State = null;
19861994
m_MapIndexInState = InputActionState.kInvalidIndex;
19871995
m_EnabledActionsCount = 0;

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,23 +4491,27 @@ internal static void DeferredResolutionOfBindings()
44914491
++InputActionMap.s_DeferBindingResolution;
44924492
try
44934493
{
4494-
for (var i = 0; i < s_GlobalState.globalList.length; ++i)
4494+
if (InputActionMap.s_NeedToResolveBindings)
44954495
{
4496-
var handle = s_GlobalState.globalList[i];
4497-
4498-
var state = handle.IsAllocated ? (InputActionState)handle.Target : null;
4499-
if (state == null)
4496+
for (var i = 0; i < s_GlobalState.globalList.length; ++i)
45004497
{
4501-
// Stale entry in the list. State has already been reclaimed by GC. Remove it.
4502-
if (handle.IsAllocated)
4503-
s_GlobalState.globalList[i].Free();
4504-
s_GlobalState.globalList.RemoveAtWithCapacity(i);
4505-
--i;
4506-
continue;
4507-
}
4498+
var handle = s_GlobalState.globalList[i];
45084499

4509-
for (var n = 0; n < state.totalMapCount; ++n)
4510-
state.maps[n].ResolveBindingsIfNecessary();
4500+
var state = handle.IsAllocated ? (InputActionState)handle.Target : null;
4501+
if (state == null)
4502+
{
4503+
// Stale entry in the list. State has already been reclaimed by GC. Remove it.
4504+
if (handle.IsAllocated)
4505+
s_GlobalState.globalList[i].Free();
4506+
s_GlobalState.globalList.RemoveAtWithCapacity(i);
4507+
--i;
4508+
continue;
4509+
}
4510+
4511+
for (var n = 0; n < state.totalMapCount; ++n)
4512+
state.maps[n].ResolveBindingsIfNecessary();
4513+
}
4514+
InputActionMap.s_NeedToResolveBindings = false;
45114515
}
45124516
}
45134517
finally

0 commit comments

Comments
 (0)