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"

[C++] How can i convert my mousepos to world position?

 UWorld* world = GetWorld();
     if (world)
         APlayerController* pc = world->GetFirstPlayerController();
         FVector2D mousePos = FVector2D(0,0);
         FVector& worldpos = FVector(mousePos.X,mousePos.Y,0);
         FVector& dir = FVector(0, 0, 0);
         pc->DeprojectMousePositionToWorld(worldpos, dir); //I get an error here

The Error :"error C4239: nonstandard extension used : 'initializing' : conversion from 'FVector' to 'FVector &'"

what does this mean ? and how can i fix this ?

Product Version: Not Selected
more ▼

asked Jan 20 '15 at 03:02 PM in C++ Programming

avatar image

116 16 23 41

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

1 answer: sort voted first

That error is generated when MSVC allows you to do something that isn't standards compliant C++. There should be extra information in the output window explaining what rule was violated: http://msdn.microsoft.com/en-us/library/186yxbac.aspx

In your case, you're taking a reference to a temporary FVector, which is unsafe as the reference immediately becomes invalid:

 FVector& worldpos = FVector(mousePos.X,mousePos.Y,0);
 FVector& dir = FVector(0, 0, 0);

You'll want to initialize those by value instead:

 FVector worldpos = FVector(mousePos.X,mousePos.Y,0);
 FVector dir = FVector(0, 0, 0);
more ▼

answered Jan 20 '15 at 03:20 PM

avatar image

Jamie Dale STAFF
7.5k 177 67 305

avatar image SiraX Nov 10 '15 at 06:53 PM

Can you tell me or show me how to get my mouse position in a vector location in blueprint? I want to launch my character towards my mouse. Maybe you can help me with both

avatar image Doug E ♦♦ STAFF Nov 10 '15 at 08:46 PM

Hey SiraX-

If you're trying to to convert the mouse position to world space in blueprints then you will need to start with a Get Player Controller node and from the return value create a GetMousePosition node. Then right click the in the event graph and, depending on the blueprint you're in, uncheck "context sensitivity" and search for ConvertScreenLocationToWorldSpace. The Location X and Location Y of the mouse node can be wired into the Screen X and Screen Y respectively.


Doug Wilson

avatar image SiraX Nov 11 '15 at 06:21 PM

Thanks for the quick answer, I couldn't find the post earlier. I have the following Blueprint now: http://prntscr.com/91n9uh . How do I continue now? I want to teleport the character to the location of my mouse. I heard about LineTraceByChannel but I don't understand the 'Start' and 'End'. I'm kind of new to UE4 EDIT: I just played a bit, would http://prntscr.com/91nbcm work?

avatar image Doug E ♦♦ STAFF Nov 11 '15 at 06:56 PM

The node used in your screenshot is "Convert Mouse Location to World Space" whereas the node you're looking for is "Convert Screen Location to World Space". The target for this node is the player controller and the ScreenX and ScreenY inputs match to the X & Y of the Get Mouse Position node. With this you shouldn't need to split the struct pin from the Line Trace node.

avatar image SiraX Nov 12 '15 at 08:04 PM

http://prntscr.com/921yc2 This is what I have right now but I've tested it and it doesn't work. I really don't know about that line trace by channel :c

avatar image SiraX Nov 15 '15 at 04:03 PM

I got it...

avatar image SiraX Nov 11 '15 at 09:11 PM

Oh sorry I read Convertmouselocation too often now, i will try it out tomorrow and reply here then

(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