x

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 resolve a focus issue in Slate?

Hey everyone,

hoping there's someone out there that can point me in the right direction - I've been fighting with this for a while now and it's driving me up a wall.

Here's the issue:

I have a game, with ESC bound to toggle an in-game menu and at the same time pause the game. That works excellently, and I can hit ESC while the menu is up to toggle the menu again and unpause the game (I've got a OnKeyDown event handler in the slate widget taking care of that.

Now here's the rub: If I click anywhere within the window with the mouse while the game is paused and the menu is up, I seem to lose focus on the widget and the ESC press is no longer caught in the OnKeyDown handler.

I've tried hooking up handlers for OnKeyboardFocusLost, OnKeyboardFocusReceived and OnKeyboardFocusChanging but that didn't get me much further as far as trying to force focus to stay on the slate widget.

Can anyone give me any pointers as to how I should approach this, or maybe even check globally for that keypress instead of just inside this specific widget?

Thanks in advance!

Product Version: Not Selected
Tags:
more ▼

asked Apr 24 '14 at 08:48 PM in C++ Programming

avatar image

ReqPro
54 9 12 14

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

It's a bit heavy handed but you could try using OnPreviewKeyDown, however if your menu is losing focus I'm not sure that would help.

more ▼

answered Apr 24 '14 at 08:58 PM

avatar image

Jamie Dale STAFF
7.4k 176 66 304

avatar image ReqPro Apr 24 '14 at 09:07 PM

Hi Jamie, and thanks for taking the time to respond.

Unfortunately I just tried this and it didn't work - I think I may have found a solution though. It's kind of ugly and I really should try to find a better solution, but here it is: inside the widget's Tick I test to see if the in-game menu is open (a flag in my gamestate) and if it is, I simply force focus to the widget by calling FSlateApplication::Get().SetKeyboardFocus(SharedThis(this));

Hopefully someone can give me a pointer to a better solution - to me it seems really brute-force'ish to do it this way and it hurts my professional pride :P

Best regards, ReqPro.

avatar image Jamie Dale STAFF Apr 24 '14 at 10:20 PM

I've had a bit of a play around with this, and you might be able to create a full-screen container for your menu, whose sole job it is to catch any stray mouse clicks.

I'm not sure if this will be compatible with how your menu is set-up, but this is basically a modified version of the Slate HUD sample on the wiki, with the widget that's added to the viewport vetoing all mouse events.

With this running in my game, I'm not able to interact with the main viewport until I hide the widget by pressing C (I didn't use Escape since I was testing via PIE).

avatar image Jamie Dale STAFF Apr 24 '14 at 10:22 PM

Just to clarify, with this solution it would be the responsibility of the container widget to handle closing the menu when escape is pressed.

avatar image ReqPro Apr 24 '14 at 10:32 PM

Hi Jamie, thanks again...

Your solution is pretty much exactly what I'd done, except that I didn't think of intercepting the mouse click inside the widget.... (duh)

Thanks for your input!

(comments are locked)
10|2000 characters needed characters left
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