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"

Accesing mouse position/coordinates in C++


I have set up my mouse control according to this tutorial.

Great, except the tutorial finishes off with "When you play the map, you should now see the cursor. However, unless you have set up some sort of behavior (via C++ code or Blueprint), you will get no responses at this time" and is completely unhelpful in giving me hints on where to start with that.

I've been googling around trying to find something, but to no avail. The closest I could find was this, which destroyed my project.

What I wanna know is, how can I access my new class from my C++ pawn code and get and use the mouse coordinates? Getting them in 2D vector form would be ideal, but anything goes. As my project develops I will need to implement for complex mouse uses but for now I just need a starting point.

Can anyone help me please? Thanks!

Product Version: UE 4.10
more ▼

asked Dec 12 '15 at 05:25 AM in C++ Programming

avatar image

21 1 2 3

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

1 answer: sort voted first

You'll want to use the GetMousePosition() method of the Player Controller. Here's a simple example, where there is only a single PlayerController in the world:

 float mouseX;
 float mouseY;
 UGameplayStatics::GetPlayerController(GetWorld(), 0)->GetMousePosition(mouseX, mouseY);
 UE_LOG(MyLog, Warning, TEXT("Mouse Location: %f, %f"), mouseX, mouseY);

You'll need these two libraries included in your .cpp file:

 #include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
 #include "Runtime/Engine/Classes/GameFramework/PlayerController.h"
more ▼

answered Apr 13 '18 at 05:32 AM

avatar image

11 7 3

avatar image arskon03 Oct 07 '18 at 08:31 PM

I am having some trouble with this. I've done exactly what you told to but every time I play the engine crashes

(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