[Help required] Can't give keyboard focus back to game after using UI element
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 :)
asked Apr 12 '17 at 09:34 AM in Blueprint Scripting
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.
answered Apr 12 '17 at 02:42 PM
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.
answered Apr 13 '17 at 06:34 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here