-
Notifications
You must be signed in to change notification settings - Fork 326
FIX: disabling the InputSystemUIInputModule component resets all actions to None #2192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e433739
6879065
f08c6fd
d94b0e6
6aa15c7
f4bed15
5c996c0
29fcc49
44831d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1528,6 +1528,17 @@ | |
set => SwapAction(ref m_TrackedDevicePositionAction, value, m_ActionsHooked, m_OnTrackedDevicePositionDelegate); | ||
} | ||
|
||
// We should dispose the static default actions thing because otherwise it will survive domain reloads | ||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] | ||
static void ResetDefaultActions() | ||
{ | ||
if (defaultActions != null) | ||
{ | ||
defaultActions.Dispose(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess, calling Dispose is just to stay on the safe side since the only data default actions stores is a ref to ScriptableObject that won't survive even with domain reload off. It will be in this intermediate state though, where its native data is gone but the instance is not null until the next gc run (however you'll see it as "null" in debugger, and ==null will be true as well, thanks to Unity's Equals overload for all Object descendants). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this comment imply that it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I wasn't clear, pardon. DefaultActions is fine to check for null like above since it's not destroyed natively. What is in the intermediate state happens to be aggregated in defaultActions (DefaultActions has a ref to ScriptableObject, so it's the ScriptableObject would have to be checked with ReferenceEquals if we needed to, but we don't). |
||
defaultActions = null; | ||
} | ||
} | ||
Check warning on line 1540 in Packages/com.unity.inputsystem/InputSystem/Plugins/UI/InputSystemUIInputModule.cs
|
||
|
||
/// <summary> | ||
/// Assigns default input actions asset and input actions, similar to how defaults are assigned when creating UI module in editor. | ||
/// Useful for creating <see cref="InputSystemUIInputModule"/> at runtime. | ||
|
@@ -1665,7 +1676,12 @@ | |
InputActionState.s_GlobalState.onActionControlsChanged.RemoveCallback(m_OnControlsChangedDelegate); | ||
DisableAllActions(); | ||
UnhookActions(); | ||
UnassignActions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ^ This line is very wrong, it results in user data being lost on component deactivation. |
||
|
||
// In the case we've been initialized with default actions, we want to release them | ||
if (defaultActions != null && defaultActions.asset == actionsAsset) | ||
{ | ||
UnassignActions(); | ||
} | ||
|
||
base.OnDisable(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great you added a specific test for the regression