Skip to content

Commit d5185f6

Browse files
committed
FIX: InputActionReference when using FEPM (ISX-1968)
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 483d115 commit d5185f6

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

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)