I find myself in a bit of an annoying issue to which I could not get a proper solution.
I made an inventory widget that pops up when pressing “I” and closes down the same way. When the inventory is opened, the crosshair dissapears and the mouse cursor becomes visible to use in the inventory menu.
When I press the “I” button and the inventory opens, and press it again without having clicked anything, the inventory disappears and the mouse cursor automatically goes back to camera control.
However, if I open the inventory and click somewhere, and then close it again by pressing “I”, the mouse cursor stays there until I left click within the viewport first to enable the camera controls again.
This video should give a better picture, should my explanation be vague: - YouTube
Does anyone know how I can force the mouse input to go back to the camera controls without having to click the viewport first?
I find this also happens on default when creating the first person template. It’s not just in the editor. If I launch the game externally, the issue remains.
Hi, thanks for your reply. Unfortunately the “Set Focus To Game Viewport” node does not seem to affect anything. I tried placing this node between or after the nodes that hide the inventory and which should give the controls back, but nothing changes.
Also the mouse cursor dissapears sometimes when I close the inventory, but I still need to click the viewport.
Is there a certain way I need to place this node or could there be anything from UMG conflicting with it?
@Nsomnia,
Ooh, that tutorial looks quite good actually. Better than the one I’m currently following because in here everything is actually explained rather than just “do this, then do that, and click on this, enter that and fill in this and click compile” without telling why or what we’ve actually been doing. I think I’ll check this tutorial out instead. Thanks!
I only had to add the “Set Input Mode Game Only” node after the node that closes the inventory and make the target “Get Player Controller”. Now the cursor automatically returns to the camera control after closing the inventory.
@Nsomnia This helped alot BUT Did you receive any errors in the play editor when pressing your inventory key? The attached image is what errors I am receiving upon key pressed and key pressed again.
When I wire the player controller to the GetPlayerController. I receive no error when I press the key the first time, however when I press it again it will not close the widget.
When you *Set Input Mode UI Only, *you prevent the *Player Controller *from processing inputs (as the name implies!) - the widget has the exclusivity from now on and the input action can no longer be detected. Consider implementing removing the widget from the viewport *inside *the widget itself. Widgets can override *onKeyDown *and remove *self *from the viewport (or any other parent container). Either that, or do not exclude the controller through the input mode.