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

**URL:** <https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496>\
**Category:** Character & Animation\
**Tags:** playercontroller, fvector, unreal-engine, mouse-position, question, CPP\
**Created:** [January 20, 2015, 3:02pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496 "2015-01-20T15:02:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gunschlinger](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Gunschlinger](https://forums.unrealengine.com/u/Gunschlinger)\
**Post date:** [January 20, 2015, 3:02pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/1 "2015-01-20T15:02:37Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![Jamie\_Dale](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jamie_dale/32/1165413_2.png) [@Jamie\_Dale](https://forums.unrealengine.com/u/Jamie_Dale)\
**Post date:** [January 20, 2015, 3:20pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/2 "2015-01-20T15:20:11Z")

</div>

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

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_496914ac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_496914ac1](https://forums.unrealengine.com/u/anonymous_user_496914ac1)\
**Post date:** [November 10, 2015, 6:53pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/3 "2015-11-10T18:53:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [November 10, 2015, 8:46pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/4 "2015-11-10T20:46:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_496914ac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_496914ac1](https://forums.unrealengine.com/u/anonymous_user_496914ac1)\
**Post date:** [November 11, 2015, 6:21pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/5 "2015-11-11T18:21:56Z")

</div>

Thanks for the quick answer, I couldn’t find the post earlier. I have the following Blueprint now: [Screenshot by Lightshot](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 [Screenshot by Lightshot](http://prntscr.com/91nbcm) work?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_2b03d27c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_2b03d27c](https://forums.unrealengine.com/u/anonymous_user_2b03d27c)\
**Post date:** [November 11, 2015, 6:56pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/6 "2015-11-11T18:56:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_496914ac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_496914ac1](https://forums.unrealengine.com/u/anonymous_user_496914ac1)\
**Post date:** [November 11, 2015, 9:11pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/7 "2015-11-11T21:11:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_496914ac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_496914ac1](https://forums.unrealengine.com/u/anonymous_user_496914ac1)\
**Post date:** [November 12, 2015, 8:04pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/8 "2015-11-12T20:04:27Z")

</div>

[Screenshot by Lightshot](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

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_496914ac1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_496914ac1](https://forums.unrealengine.com/u/anonymous_user_496914ac1)\
**Post date:** [November 15, 2015, 4:03pm UTC](https://forums.unrealengine.com/t/c-how-can-i-convert-my-mousepos-to-world-position/304496/9 "2015-11-15T16:03:27Z")

</div>

I got it…
