How do I de-highlight a UI Selectable after disabling mouse input?

I have a UI element in the center of the screen. If you hover over it with the mouse, it becomes highlighted. Now disable mouse input with Cursor.lockState = CursorLockMode.Locked and hide the mouse with Cursor.visible = false. However, the UI element remains in a highlighted state. How can I trigger the event system to transition this from Highlighted to Normal state?

I’ve discovered two ways to do this:

  1. Call ClearSelection on the active input module to
    deselect/unhighlight all UI
    elements. However, this is a protected class, so it’s only accessible from within custom input modules that derive from the PointerInputModule.
  2. Use the ExecuteEvents helper
    class to send a pointer exit event
    to a specific game object to
    unhighlighted that object.

Example:

var pointer = new PointerEventData(EventSystem.current);
ExecuteEvents.Execute(eventSystem.currentSelectedGameObject, pointer, ExecuteEvents.pointerExitHandler);

@PsyDev

Hi, calling OnDeselect() manually worked for me on 5.5.0f3. Tested on a simple button like this:

yourButton.OnDeselect(null);

and the ‘yourButton’ returned to normal state.