Skip to content

FIX: Fixed errors caused by recreation of DefaultInputActions instance in InputSystemProvider #2149

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

Merged
merged 2 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ however, it has to be formatted properly to pass verification tests.
- Fixed an issue where ButtonStates are not fully updated when switching SingleUnifiedPointer. [ISXB-1356](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1356)
- Fixed errors when pasting composite parts into non-composites. [ISXB-757](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-757)
- Fixed an issue where updating the InputSystem outside of the dynamic Update would lead to UI input and navigation events get lost. [ISXB-1313](https://issuetracker.unity3d.com/issues/ui-onclick-events-sometimes-do-not-trigger-when-manual-update-is-utilized-with-input-system)
- Fixed an issue causing a number of errors to be displayed when using `InputTestFixture` in playmode tests with domain reloading disabled on playmode entry [ISXB-1446](https://issuetracker.unity3d.com/product/unity/issues/guid/ISXB-1446)

### Changed
- Changed enum value `Key.IMESelected` to obsolete which was not a real key. Please use the ButtonControl `imeSelected`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,23 @@ static InputActionAssetVerifier()
public void Verify(InputActionAsset asset,
ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
{
// Note that we never cache this to guarantee we have the current configuration.
var config = InputSystemProvider.Configuration.GetDefaultConfiguration();
Verify(asset, ref config, reporter);
// Note:
// PWA has initial state check true for "Point" action, DefaultActions do not, does it matter?
//
// Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type.
// This is not available in UI configuration, but InputActionRebindingExtensions suggests this.
//
// Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick".
// Is this intentional? Are requirements different?
var context = new Context(asset, reporter, DefaultReportPolicy);
context.Verify(actionNameOrId: InputSystemProvider.Actions.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
context.Verify(actionNameOrId: InputSystemProvider.Actions.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
context.Verify(actionNameOrId: InputSystemProvider.Actions.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button");
context.Verify(actionNameOrId: InputSystemProvider.Actions.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button");
context.Verify(actionNameOrId: InputSystemProvider.Actions.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: InputSystemProvider.Actions.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: InputSystemProvider.Actions.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: InputSystemProvider.Actions.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
}

#endregion
Expand Down Expand Up @@ -111,28 +125,6 @@ public void Verify(string actionNameOrId, InputActionType actionType, string exp
private HashSet<string> missingPaths; // Avoids generating multiple warnings around missing map
private ReportPolicy policy;
}

private static void Verify(InputActionAsset asset, ref InputSystemProvider.Configuration config,
ProjectWideActionsAsset.IReportInputActionAssetVerificationErrors reporter)
{
// Note:
// PWA has initial state check true for "Point" action, DefaultActions do not, does it matter?
//
// Additionally note that "Submit" and "Cancel" are indirectly expected to be of Button action type.
// This is not available in UI configuration, but InputActionRebindingExtensions suggests this.
//
// Additional "LeftClick" has initial state check set in PWA, but not "MiddleClick" and "RightClick".
// Is this intentional? Are requirements different?
var context = new Context(asset, reporter, DefaultReportPolicy);
context.Verify(actionNameOrId: config.PointAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
context.Verify(actionNameOrId: config.MoveAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
context.Verify(actionNameOrId: config.SubmitAction, actionType: InputActionType.Button, expectedControlType: "Button");
context.Verify(actionNameOrId: config.CancelAction, actionType: InputActionType.Button, expectedControlType: "Button");
context.Verify(actionNameOrId: config.LeftClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: config.MiddleClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: config.RightClickAction, actionType: InputActionType.PassThrough, expectedControlType: "Button");
context.Verify(actionNameOrId: config.ScrollWheelAction, actionType: InputActionType.PassThrough, expectedControlType: nameof(Vector2));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ namespace UnityEngine.InputSystem.Plugins.InputForUI

internal class InputSystemProvider : IEventProviderImpl
{
Configuration m_Cfg;

InputEventPartialProvider m_InputEventPartialProvider;

DefaultInputActions m_DefaultInputActions;
InputActionAsset m_InputActionAsset;

InputActionReference m_PointAction;
Expand Down Expand Up @@ -86,28 +85,37 @@ public void Initialize()
m_TouchState.Reset();
m_SeenTouchEvents = false;

m_Cfg = Configuration.GetDefaultConfiguration();

SelectInputActionAsset();
RegisterActions();

// TODO make it configurable as it is not part of default config
// The Next/Previous action is not part of the input actions asset
RegisterFixedActions();

InputSystem.onActionsChange += OnActionsChange;
}

public void Shutdown()
{
UnregisterActions();
UnregisterFixedActions();

m_InputEventPartialProvider.Shutdown();
m_InputEventPartialProvider = null;

if (m_DefaultInputActions != null)
{
m_DefaultInputActions.Dispose();
m_DefaultInputActions = null;
}

InputSystem.onActionsChange -= OnActionsChange;
}

public void OnActionsChange()
{
UnregisterActions();

m_Cfg = Configuration.GetDefaultConfiguration();
SelectInputActionAsset();
RegisterActions();
}

Expand Down Expand Up @@ -584,7 +592,7 @@ void OnScrollWheelPerformed(InputAction.CallbackContext ctx)
}));
}

void RegisterNextPreviousAction()
void RegisterFixedActions()
{
m_NextPreviousAction = new InputAction(name: "nextPreviousAction", type: InputActionType.Button);
// TODO add more default bindings, or make them configurable
Expand All @@ -604,19 +612,17 @@ void UnregisterFixedActions()

void RegisterActions()
{
m_InputActionAsset = m_Cfg.ActionAsset;

// Invoke potential lister observing registration
s_OnRegisterActions?.Invoke(m_InputActionAsset);

m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.PointAction));
m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MoveAction));
m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.SubmitAction));
m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.CancelAction));
m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.LeftClickAction));
m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.MiddleClickAction));
m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.RightClickAction));
m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(m_Cfg.ScrollWheelAction));
m_PointAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.PointAction));
m_MoveAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MoveAction));
m_SubmitAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.SubmitAction));
m_CancelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.CancelAction));
m_LeftClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.LeftClickAction));
m_MiddleClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.MiddleClickAction));
m_RightClickAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.RightClickAction));
m_ScrollWheelAction = InputActionReference.Create(m_InputActionAsset.FindAction(Actions.ScrollWheelAction));

if (m_PointAction != null && m_PointAction.action != null)
m_PointAction.action.performed += OnPointerPerformed;
Expand Down Expand Up @@ -648,10 +654,6 @@ void RegisterActions()
}
else
m_InputActionAsset.Enable();

// TODO make it configurable as it is not part of default config
// The Next/Previous action is not part of the input actions asset
RegisterNextPreviousAction();
}

void UnregisterActions()
Expand Down Expand Up @@ -688,49 +690,43 @@ void UnregisterActions()

if (m_InputActionAsset != null)
m_InputActionAsset.Disable();

UnregisterFixedActions();
}

public struct Configuration
void SelectInputActionAsset()
{
public InputActionAsset ActionAsset;
public string PointAction;
public string MoveAction;
public string SubmitAction;
public string CancelAction;
public string LeftClickAction;
public string MiddleClickAction;
public string RightClickAction;
public string ScrollWheelAction;
// Only use default actions asset configuration if (ISX-1954):
// - Project-wide Input Actions have not been configured, OR
// - Project-wide Input Actions have been configured but contains no UI action map.
var projectWideInputActions = InputSystem.actions;
var useProjectWideInputActions =
projectWideInputActions != null &&
projectWideInputActions.FindActionMap("UI") != null;

public static Configuration GetDefaultConfiguration()
// Use InputSystem.actions (Project-wide Actions) if available, else use default asset if
// user didn't specifically set one, so that UI functions still work (ISXB-811).
if (useProjectWideInputActions)
m_InputActionAsset = InputSystem.actions;
else
{
// Only use default actions asset configuration if (ISX-1954):
// - Project-wide Input Actions have not been configured, OR
// - Project-wide Input Actions have been configured but contains no UI action map.
var projectWideInputActions = InputSystem.actions;
var useProjectWideInputActions =
projectWideInputActions != null &&
projectWideInputActions.FindActionMap("UI") != null;

// Use InputSystem.actions (Project-wide Actions) if available, else use default asset if
// user didn't specifically set one, so that UI functions still work (ISXB-811).
return new Configuration
{
ActionAsset = useProjectWideInputActions ? InputSystem.actions : new DefaultInputActions().asset,
PointAction = "UI/Point",
MoveAction = "UI/Navigate",
SubmitAction = "UI/Submit",
CancelAction = "UI/Cancel",
LeftClickAction = "UI/Click",
MiddleClickAction = "UI/MiddleClick",
RightClickAction = "UI/RightClick",
ScrollWheelAction = "UI/ScrollWheel",
};
if (m_DefaultInputActions is null)
m_DefaultInputActions = new DefaultInputActions();

m_InputActionAsset = m_DefaultInputActions.asset;
}
}

public static class Actions
{
public readonly static string PointAction = "UI/Point";
public readonly static string MoveAction = "UI/Navigate";
public readonly static string SubmitAction = "UI/Submit";
public readonly static string CancelAction = "UI/Cancel";
public readonly static string LeftClickAction = "UI/Click";
public readonly static string MiddleClickAction = "UI/MiddleClick";
public readonly static string RightClickAction = "UI/RightClick";
public readonly static string ScrollWheelAction = "UI/ScrollWheel";
}

internal static void SetOnRegisterActions(Action<InputActionAsset> callback)
{
s_OnRegisterActions = callback;
Expand Down