[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->GetMousePosition(mousePos.X,mousePos.Y);
		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 ?

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);

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

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.

Cheers

Thanks for the quick answer, I couldn’t find the post earlier. I have the following Blueprint now: Screenshot by Lightshot . 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 Screenshot by Lightshot work?

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.

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

Screenshot by Lightshot 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

I got it…