How do you center the mouse cursor?

So in my first person game I have a crosshair that’s locked at the center of the screen and I also have a click event. The problem is the click event isn’t activating when I move the crosshair over it, it only works when the mouse cursor is over it (which is invisible). So I’m trying to figure out two ways to solve this.

  1. Is there a way to lock the mouse in the center of the screen. I’ve been trying to do this but I’m not sure where to put the blueprint (I assume it goes in the player controller but I could be wrong). I would still be able to move the camera as normal but the mouse cursor would always be locked in the center of the screen.

  2. Is there a way for the click event to detect if the crosshair is overlapping with the object instead of the cursor? I’ve tried this in lots of different ways and nothing’s worked so that’s probably not the best option.

So how can I solve this problem?

UPDATE: So I made a line trace which is in my player controller class but it still doesn’t work. It seems to do what it’s supposed to do which is detect where my crosshair is but my click events continue to only detect when the mouse is clicking on the objects and not the crosshair.
Here’s the line trace blueprint:

UPDATE 2: Ok I put that blueprint in the hud class and it still doesn’t work. How do I make it work? I’m starting to think I need a way for it to ignore the mouse cursor and only focus on the crosshair. So how do I make this work?

There are a few questions about this and no answers. You could instead set up a ray trace from the centre of the camera and create hit events instead of click events

Here’s my attempt at a ray trace:

This still doesn’t work and I’ve tried putting it in my player controller and my crosshair blueprint but neither one of them works. I’m new to tracing and I know there are different types of tracing so I’m not sure if I’m using the right type of tracing. Again all I want is for the click events to detect if the crosshair is clicking on the object instead of the mouse.

World static is one issue. You should use a line trace not a box trace. Use a line trace by channel.

Secondly to set the mousecursor to the center of the screen use GetViewportSize break the vector2d structure (blue) and divide x and y by 2 that will give you the center of the screen. now you can use something like th efollowing but note it will onyl work on widgets (UMG aka the HUD or GUI so youd have to make an invisible widget.

If you download and install Ramas extra blueprints node plugin (google that) called victoryPlugin.zip on the wiki he has all sorts of extra BP nodes including the one on the bottomof the picture that does exactly what you want.

If this helped you clear stuff up or answer your question dont forget to select an answer so that people googling/searching the same question in the future know what helped you the most and can help them.

[http://i.imgur.com/z2VIwwe.png][1]

Heres some more you can do in the HUD class ONLY!

[http://i.imgur.com/YUoflwo.png][3]

Lastly one thing I thought of in someone who asked something similar is to lock the cursor using the lock mouse or lock cursor or whatever node when it hits the vector2d x,y of the screen center

Ok so I made another line trace which I put in my player controller class.

This still doesn’t work and I’m really confused. I have a blueprint which can draw a crosshair in the center of the screen so why is it so hard for click events to detect if there’s an overlap with the center of the screen? Do I have to put that blueprint in the HUD class instead of the player controller class? I’m really confused and I really need help.

UPDATE: So I changed the draw debug type to 1 frame and now it draws a line that goes towards the crosshair (in the center of the screen). So it appears to be detecting the center of the screen but for some strange reason it still only detects if the invisible mouse is clicking the button and not the crosshair. I really need help with this and I feel like I’m close to figuring out what’s going on but I still don’t know how to solve this problem. Can someone please help me solve this problem?

brandon , try multiplying the forward vector with 1500 or simular value! Dont know what you mean with the button or mouse! Use print string on important values to debug.

Alright I figured it out. You can lock the thread now.

can you share the solution, ive been struggling with this myself

Sad to see no solution shared…

Can you share your solution?

I just set up a line trace in my player controller.