Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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: alt text

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?

Product Version: UE 4.8
line trace.png (201.1 kB)
more ▼

asked Sep 03 '15 at 04:44 AM in Blueprint Scripting

avatar image

88 28 38 45

avatar image Steve_T Sep 03 '15 at 04:07 PM

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

avatar image Brandon236 Sep 03 '15 at 09:44 PM

Here's my attempt at a ray trace: alt text 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.

ray trace.png (201.1 kB)
avatar image AndreykaMrPvP Jun 17 '16 at 10:57 PM

alt text

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Can you share your solution?

more ▼

answered Jun 02 '16 at 09:53 PM

avatar image

26 1 2 9

avatar image Brandon236 Jun 02 '16 at 11:44 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.


alt text

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


alt text

alt text

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

more ▼

answered Sep 03 '15 at 10:02 PM

avatar image

1.8k 67 27 137

avatar image Brandon236 Sep 04 '15 at 01:08 AM

Ok so I made another line trace which I put in my player controller class. alt text 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?

line trace.png (201.1 kB)
avatar image charisti Sep 05 '15 at 01:35 PM

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.

avatar image Brandon236 Sep 06 '15 at 02:14 AM

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

avatar image Baserage Oct 08 '15 at 01:08 AM

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

avatar image WilliamHooper May 17 '16 at 11:12 PM

Sad to see no solution shared...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question