I’m trying to code (using blueprints) a double type of behavior for the mouse. In normal mode, I move around the level in first person view, and this is all working well.
When I right-click, the game switches to Inventory mode, and display the user’s inventory. In this mode, movement is disabled, and I show the mouse cursor. To do that, I created a custom PlayerController blueprint and set it in my gamemode, and I set “Show Mouse Cursor” to true. This is also working well.
The problem happens when I go back to normal mode after doing this. All I do is set “Show Mouse Cursor” back to false, but after doing this, the mouse can’t go very far, and it seems locked inside the viewport (even if I can’t see the cursor)… So if I move my mouse left, the camera turns left, as expected, but if I keep moving the mouse left, it eventually stops turning. Switching to inventory mode at this point shows the mouse at the complete left of the viewport.
Also, I’ve setup dual input binding for the switch to inventory mode. Right click, and spacebar. All the above behavior is when I use right-click. If I use spacebar, the mode switches properly (i.e. the hud shows the inventory), but when going back to normal mode, I don’t get mouse input anymore. I have to click to get it back.
This is all so weird and confusing, thanks for the help!
When you exit inventory mode, did you remove the viewport from the screen and return to your in game HUD?
Inventory mode is basically a boolean value, which in the HUD blueprint enables the drawing of inventory slots.
This is from the blueprint I derived from Character, which handles camera and movement:
Set Inventory Mode and Set Normal Mode, are 2 functions defined in my custom Player Controller descendant blueprint, which only set the Show Mouse Cursor value to true/false, respectively.
I don’t have an inventory blueprint per se… Here’s how this is all setup…
Custom HUD blueprints always draws a belt at the bottom, and when in inventory mode, draws the full inventory:
(Nothing funny going in the macro or draw functions, simple calls to Draw Texture Simple)
Custom Character blueprint handles all input:
Camera/character control is pretty standard, simple calls to Add Yaw/Pitch and Add movement
Custom Player Controller only has 2 functions, nothing else:
That’s practically ALL my blueprints stuff… The only thing that affects the mouse in my code is the changes to Show Mouse Cursor… I don’t do anything else than that.
When I first launch the game, everything works fine, but as soon as I do ShowMouseCursor(false) and ShowMouseCursor(true) in succession, the mouse becomes restrained to the window and limits the range I can rotate the camera.
If I do the toggling with space bar (both space bar and right-click are assigned to the ToggleInvMode input event), then I completely lose input events after going back to normal mode, until I click in the window (I don’t see the mouse cursor either, just have to click to re-enable input)
Can you show me the full inventory blueprint? is the mouse trapped completely in the bounds of the inventory box or does it still allow you access to your full screen but affects movement (as you mentioned)?
I’m happy to hear you found a solution to your question. I will mark this as answered for tracking purposes.
Just did a bit more testing…
If I ONLY use space bar (i.e. launch the game, then use space bar to toggle inventory mode on/off), everything works perfectly.
While in inventory mode, the mouse cursor is restrained to the window, but when I toggle back to normal mode (with space bar), everything works just as when I launch, perfectly.
As soon as I right-click to toggle, it becomes screwed up like I described.
OK I fixed it!
Thanks for your time anyway