The default behavior of the InputSystem when used with UI Toolkit is to cause deselection of the focused visual element when mouse-clicking anywhere in the “background” area. (I don’t understand why “deselect on background click” is the default behavior. It’s almost never something you want.)
As far as I know, the only way to prevent this behavior is to use a custom EventSystem
with a properly configured InputSystemUIInputModule
component, followed by a call to SetUITookitEventSystemOverride
before the custom event system receives its Start
callback . This is true even with InputSystem version 1.8, whose documentation suggests you shouldn’t need to use SetUITookitEventSystemOverride
anymore.
So here is my feature request. Can we get some sort of project-wide InputSystem setting that disables “deselect on background click”? In fact, can we get the ability to configure the other settings only exposed through the InputSystemUIInputModule module (e.g., “cursor lock behavior”)?
In case anyone finds this post and wants to know how to prevent deselect on background click as things stand today, here are the steps:
- Add EventSystem and InputSystemUIInputModule components onto a GameObject in your scene.
- Configure the input system UI input module component by turning off “deselect on background click”.
- Configure the input system UI input module component by settings its input “Actions Asset” to the project-wide input actions asset.
- Create a custom C# script component on the same GameObject as the EventSystem and InputSystemUIInputModule components. Something like the following:
[RequireComponent(typeof(InputSystemUIInputModule))]
[RequireComponent(typeof(EventSystem))]
public class InputConfigurator : MonoBehaviour
{
void Awake()
{
EventSystem.SetUITookitEventSystemOverride(
this.GetComponent<EventSystem>(),
sendEvents: true,
createPanelGameObjectsOnStart: true);
}
}