How to Automatically Return Focus to Viewport

Hi friends,

I am trying to understand the focus system in Slate/UMG. My problem is as follows:

  1. I set the player’s custom cursor to something other than Default (e.g. TextBeam).
  2. I click on a button. The viewport loses focus.
  3. I mouse over viewport, but Default cursor shows because viewport lacks focus.
  4. I click, and viewport regains focus. Custom cursor appears.

I want to avoid clicking on the viewport to regain focus. Is there a way to make Slate automatically give focus back to the viewport once a mouse click ends or the mouse leaves a button/widget?

Hi! This is rather usual logic about focus. Every widget that is focusable gets focus when clicked or when appears while previous focused widget lost it. UWidget class has bIsFocusable property that controls if it can receive Focus. Focus is controlled by FSlateApplication. Take a look at this class FSlateApplication | Unreal Engine Documentation