Skip to content

Commit

Permalink
FIX: InputActionReference when using FEPM (ISX-1968)
Browse files Browse the repository at this point in the history
When Domain Reloads are disabled, InputActionReference instances continue to reference the "old" InputAction object from the previous PlayMode session.

This fix clears the InputAction reference when exiting PlayMode allowing it to be reloaded in the next session.
  • Loading branch information
timkeo committed Jun 18, 2024
1 parent f7cc21e commit 7fafc88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed an issue where `InputActionAsset.FindAction(string, bool)` would throw `System.NullReferenceException` instead of returning `null` if searching for a non-existent action with an explicit action path and using `throwIfNotFound: false`, e.g. searching for "Map/Action" when `InputActionMap` "Map" exists but no `InputAction` named "Action" exists within that map [ISXB-895](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-895).
- Fixed an issue where adding a `OnScreenButton` or `OnScreenStick` to a regular GameObject would lead to exception in editor.
- Fixed an issue where adding a `OnScreenStick` to a regular GameObject and entering play-mode would lead to exceptions being generated.
- 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)

### Added
- Added additional device information when logging the error due to exceeding the maximum number of events processed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ public static InputActionReference Create(InputAction action)
return reference;
}

/// <summary>
/// Clears the cached <see cref="m_Action"/> field for all current <see cref="InputActionReference"/> objects.
/// </summary>
/// <remarks>
/// After calling this, the next call to <see cref="action"/> will retrieve a new <see cref="InputAction"/> reference from the existing <see cref="InputActionAsset"/> just as if
/// using it for the first time. The serialized <see cref="m_Asset"/> and <see cref="m_ActionId"/> fields are not touched and will continue to hold their current values.
///
/// This method is used to clear the Action references when exiting PlayMode since those objects are no longer valid.
/// </remarks>
internal static void ResetCachedAction()
{
var allActionRefs = Resources.FindObjectsOfTypeAll(typeof(InputActionReference));
foreach (InputActionReference obj in allActionRefs)
{
obj.m_Action = null;
}
}

[SerializeField] internal InputActionAsset m_Asset;
// Can't serialize System.Guid and Unity's GUID is editor only so these
// go out as strings.
Expand Down
3 changes: 3 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3662,6 +3662,9 @@ internal static void OnPlayModeChange(PlayModeStateChange change)
// Nuke all InputActionMapStates. Releases their unmanaged memory.
InputActionState.DestroyAllActionMapStates();

// Clear the Action reference from all InputActionReference objects
InputActionReference.ResetCachedAction();

// Restore settings.
if (!string.IsNullOrEmpty(s_SystemObject.settings))
{
Expand Down

0 comments on commit 7fafc88

Please sign in to comment.