Skip to content

Commit 6037d4d

Browse files
authored
FIX: InputActionReference when using FEPM (ISX-1968) (#1949)
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.
1 parent f228c14 commit 6037d4d

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Packages/com.unity.inputsystem/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ however, it has to be formatted properly to pass verification tests.
2424
- 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).
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.
27+
- 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)
2728

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

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,24 @@ public static InputActionReference Create(InputAction action)
199199
return reference;
200200
}
201201

202+
/// <summary>
203+
/// Clears the cached <see cref="m_Action"/> field for all current <see cref="InputActionReference"/> objects.
204+
/// </summary>
205+
/// <remarks>
206+
/// 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
207+
/// 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.
208+
///
209+
/// This method is used to clear the Action references when exiting PlayMode since those objects are no longer valid.
210+
/// </remarks>
211+
internal static void ResetCachedAction()
212+
{
213+
var allActionRefs = Resources.FindObjectsOfTypeAll(typeof(InputActionReference));
214+
foreach (InputActionReference obj in allActionRefs)
215+
{
216+
obj.m_Action = null;
217+
}
218+
}
219+
202220
[SerializeField] internal InputActionAsset m_Asset;
203221
// Can't serialize System.Guid and Unity's GUID is editor only so these
204222
// go out as strings.

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3662,6 +3662,9 @@ internal static void OnPlayModeChange(PlayModeStateChange change)
36623662
// Nuke all InputActionMapStates. Releases their unmanaged memory.
36633663
InputActionState.DestroyAllActionMapStates();
36643664

3665+
// Clear the Action reference from all InputActionReference objects
3666+
InputActionReference.ResetCachedAction();
3667+
36653668
// Restore settings.
36663669
if (!string.IsNullOrEmpty(s_SystemObject.settings))
36673670
{

0 commit comments

Comments
 (0)