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"

[Help required] Can't give keyboard focus back to game after using UI element

Hai

So, I've made a simple text input box that can be shown and given focus on a key press ('Return' or '/'). This allows the player to press one of the 2 keys and have a text input box show, allowing them to type into it without the need to click. This is great, exactly what I need. On 'Return' pressed again, the box will be hidden and cleared, and the text will be passed to another function for processing. Again, this works fine. The thing is, after the textbox's parent panel is hidden and the game viewport is given focus, everything works fine except you have to click in the viewport before you can open the textbox again (using 'Return' or '/'). I'd like to be able to consecutively open the box, type, press enter, re-open the box and type again, without having to click in the viewport.

In case you're wondering, it's for a chat system.

I've tried using the 'clear keyboard focus' and other keyboard focus related nodes with no luck. Does anyone happen to know how I can get keyboard focus back to the game viewport, or where I need to send said focus? I really don't wanna have to keep clicking in the viewport after each message, which moves the character around.

Details (order of execution): - The input text box is an Editable Text element inside a panel. - (Player) On 'Enter' or '/' pressed, call custom function called 'Open command Box' (custom function) from referenced UI (works) - In OpenCommandBox, check if one's already open. if not, continue - Check the game isn't paused, there's no in-game context menu open (custom UI), and no inventory open. If so, continue - Set the visibility of the panel containing the editable text box to Visible. - If Return key was pressed, set the editable text box's hint text to "Chat...". If '/' key was pressed, set it to "Enter a command..." - Call 'Set User Focus' on the editable text box, with a reference to the player controller - Set boolean 'HasCommandBoxOpen' to true (prevents some other UI functions from being called, since we don't want the player opening their inventory, interacting with the world etc while using the chat box) - On text committed: use 'Switch on ETextCommit'. On Enter> call HandleCommand (custom function) then call CloseCommandBox (custom function)

In CloseCommandBox: - Set the panel's visibility to hidden - Set 'HasCommandBoxOpen' boolean to false - Call 'Set Focus to Game Viewport' function (this is where I've then tried several ways to give the keyboard focus back to the game, to no avail.

I'm probably missing something really super obvious here, but I'm new to Unreal and Blueprint, much prefer programming but I don't like C++, plus this is not my week. So any help would be greatly appreciated, and ty for your time :)

Product Version: UE 4.15
Tags:
more ▼

asked Apr 12 '17 at 09:34 AM in Blueprint Scripting

avatar image

ThatPixel
8 1 1 5

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

2 answers: sort voted first

Hi, You can use the "set input node game and ui" node to focus on the menu (you can also do "set show mouse cursor" after it) and focusing back to the game is done with the "set input mode game only" node (you can turn mouse cursor off here as well) i hope this is what you want, ive provided an image of a system using tab top open a widget with mouse curor on, and tab again to close the menu and focus on the game.

alt text

shop sytem.png (219.1 kB)
more ▼

answered Apr 12 '17 at 02:42 PM

avatar image

MakkerFelix
75 6 6 13

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

Thanks for your reply MakkerFelix, the "Set Input Mode Game Only" was one of the nodes I tried before, however now it seems to work.

more ▼

answered Apr 13 '17 at 06:34 AM

avatar image

ThatPixel
8 1 1 5

avatar image MakkerFelix Apr 13 '17 at 02:40 PM

Good to hear, have fun with your game

avatar image Todd.Vance Nov 29 '18 at 05:27 PM

Let me add to this, after having been frustrated and searching here for answers, before the "duck" finally answered me: if you had paused the game, you (duh, I guess!) have to unpause it for the focus to game to be regained!

(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