In my game, the player walks around using the mouse and can type text using the keyboard. I’ve got a UMG with a text field that accepts keyboard input. There are no other interactive elements in my widget, and I don’t need to use the mouse cursor to switch between anything.
When I use Set Input Mode Game and UI, I lose control of the game character, and moving the mouse no longer controls it. I’m already setting focus on my text field manually, so I would really prefer the UMG to just ignore all mouse input altogether.
To be more precise, I want to achieve the following result:
Keyboard input in the widget gets enabled
Mouse input stays with my character
Focus on the text field for the keyboard
Cursor stays invisible
Is it possible to do this?
Also, the cursor doesn’t disappear even though I have Hide Cursor During Capture enabled.
It turns out that using the Set Input Mode Game and UI is harmful in my case. By removing it, I’ve managed to achieve the expected result. I just connect to the Set Keyboard Focus node.
Now, my problem is that as soon as I press any button, I lose focus. If I try to do Set Keyboard Focus every frame, my text gets committed automatically as soon as I press anything. Is there any way to avoid this?
This is a bit tricky to find out but I found a simple way to do it. I’m not sure what way you’re using to get the UMG to appear or if it is persistent, but in my example I’ll be using T to spawn it, and Enter to make commit changes and make it go away.
First we set up the PlayerController blueprint to activate the widget. I first add a ‘T’ event and link it to CreateWidget and Add to Viewport node so that it’ll spawn the textbox when I press T. I then add the Set Keyboard Focus and set the reference so that it’ll let the keyboard enter input to the widget instead of the PlayerController once it is spawned.
Then we set up the widget. I made a 3D widget blueprint with a text box and a few letters for default text. I then added ‘OnTextCommitted’ as a function to the event graph. I set it to give input of the game back to the controller and then remove the widget.
I’m doing something very similar, and text gets committed every time I press any button, including mouse buttons that are assigned to movement and Esc which is supposed to open the in-game menu. Does this happen to you?
Another thing that I haven’t mentioned is that I’m using a 3D widget within a blueprint. I set focus, just like you do in your example, but when entering a trigger. If you press “T” while walking, does your character stop? It happens to me, even though I move the character with Left Mouse Button and not touching the keyboard at all.
The way it works for me, if I press T, the only way to exit the text box is to commit by pressing enter or by pressing escape. If the text box is up, my mouse will turn the camera as it usually would but I cannot move as the WASD keys are inputting into the text box. I’m not sure how it would work when moving the character with the left mouse button, as I did my example using a blank project with default pawn movement.
I set movement forward control to LMB. When I enter a trigger I use the Set Keyboard Focus in 3D widget on a text field. The focus gets set for the keyboard, but in the meantime my character stops walking, as if I stopped pressing LMB, which I didn’t. To make the character move again, I am forced to release LMB and press it again.
Thank you for the example. No need to put in a bug report as I went ahead and reported the issue in our system for you. For your reference, the bug number is UE-15753. I will say that this may just be the way things are designed but it is possible that it may be fixed. I wish I could offer a workaround for the time being but I can’t think of any.
I have already found a workaround: I use Set Keyboard Focus once on begin play and deactivate input by saving and erasing input in the text field OnTextChanged. I just thought I’d let you know about this problem I had because to me it seems counterintuitive that a function called Set Keyboard Focus affects mouse input. Thanks for all the help!