Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How can I change focus to Slate and back?

Hey everyone,

I'm building a menu in Slate, which toggles after you've hit a keyboard key (as the game itself is not mouse cursor based).

So when I hit this key, I unpossess the pawn to stop it from getting input, I ask my HUD class to make slate widgets visible, the finally set "Show Mouse Cursor" to true on the PlayerController.

When I do that, the Slate layer is not focus. I have to click on my window once, they I can drag scrollbars and such. Put another way, the first click to a button fails, the next one succeed.

After focus has been given to slate, and the menu is hidden, no mouse input goes to the Controller, so again I have to click once.

Product Version: Not Selected
more ▼

asked Jun 18 '14 at 02:21 PM in Using UE4

avatar image

256 21 25 191

avatar image joelr Jun 18 '14 at 04:10 PM

Change my problem description after digging around more. Looks like the same issue as here: https://answers.unrealengine.com/questions/51068/how-to-change-focus-between-slate-menu-and-game.html

avatar image joelr Jun 18 '14 at 08:34 PM

No exact answer yet, but the ShooterGame sample has an in-game menu that seems to work fine. I'll look into that.

avatar image Antares Jun 19 '14 at 01:26 PM

I have search a lot, still did not find how they do, I have add a basic button to there menu to see the hover effect, I have comment a lot of stuff and its still work... I start to believe this may be a property set somewhere, did you find something?

avatar image joelr Jun 19 '14 at 05:42 PM

I've been commenting out code too. Even if the menu is stripped of useful widgets, the line that makes the cursor appear is: GEngine->GameViewport->AddViewportWidgetContent(...) in ShooterIngameMenu.cpp. You can comment this line out and then cursor is no longer there.

They don't use the ShowCursor property of the PlayerController at all for this. Epic team, any hints on this?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

Hi Guys !

Just SOLVE this problem =), thanks to the ShooterGame !

So basically this is what you have to do :

Add this in your widget :

 /** says that we can support keyboard focus */
 virtual bool SupportsKeyboardFocus() const OVERRIDE{ return true; }

 FReply SBLCUIWidget::OnKeyboardFocusReceived(const FGeometry& MyGeometry, const FKeyboardFocusEvent& InKeyboardFocusEvent)
     return FReply::Handled().ReleaseMouseCapture().CaptureJoystick(SharedThis( this ), true);

Then when you want to open the menu simply do that :


And to close it :


Hope this will help you because its been 3 days I am on this !!

Bests ;)

more ▼

answered Jun 19 '14 at 07:13 PM

avatar image

71 3 3 70

avatar image joelr Jun 19 '14 at 09:47 PM

Hey, I found the same solution :)

SupportsKeyboardFocus() needs to return true if SetKeyboardFocus() is to work, because that method checks the predicate.

Then the mouse needs to be released otherwise will hide itself away as soon as you interact with Slate.

CaptureJoystick(SharedThis( this ), true) is not needed.

Alternatively, when calling SetKeyboardFocus(), also call ReleaseMouseCapture() on the SlateApplication object. This way there's no need to override OnKeyboardFocusReceived.

Thanks Antares for all the help! I wish this behavior was documented, or that at least SetMouseFocus() would exist, as Keyboard focus and mouse cursor are not obviously linked together.

avatar image joelr Jun 19 '14 at 10:54 PM

One addition: had to also override this to prevent the cursor from disappearing on left-clicks:

 FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) OVERRIDE
         //Set the keyboard focus 
         return FReply::Handled().SetKeyboardFocus(SharedThis(this), EKeyboardFocusCause::SetDirectly);

avatar image Antares Jun 20 '14 at 10:23 AM

Realy nice, I was searching for that, and thank you for the help ! I prefer to keep override of OnKeyboardFocusReceived because they do it in ShooterGame and it may be more clear (look for description of ReleaseMouseCapture they talk about doing this in reply)

Hope all of this will help other people and yes Keyboard focus mean keyboard to me and not mouse !

avatar image uced Dec 07 '15 at 09:04 PM


For anyone arriving here after hours of failures and tears^^, OnKeyboardFocusReceived is deprecated since 4.6.

Here is some working code (currently 4.10):

 virtual bool SupportsKeyboardFocus() const override { return true; }
 virtual FReply OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& InFocusEvent) override;
 FReply MyWidget::OnFocusReceived(const FGeometry& MyGeometry, const FFocusEvent& InFocusEvent)
     return FReply::Handled().ReleaseMouseCapture();



(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question