How to use GetViewProjMatrix().TransformVector(LineDirection) in UE4? I try to project a 3D vector (a direction, not a position) in screen space, but it does not return satisfying results:

 FVector LineDirectionOnScreen = 
   EdMode-&gt;ViewMatrices.GetViewProjMatrix().TransformVector(LineDirection);
 FVector2D LineDirectionOnScreen2D(
   LineDirectionOnScreen.X * 0.5f * (float)EdMode-&gt;ViewRect.Width(), 
   LineDirectionOnScreen.Y * 0.5f * (float)EdMode-&gt;ViewRect.Height());


When LineDirection is (0,0,1) it always returns a something like (0,Y) (Y can be anything), no matter how the camera is rotated.

What is wrong with my code?
I don't think you can simply use TransformVector when the matrix you're transforming by involves a projection matrix. To fully project to screen space, you have to divide by W, which TransformVector doesn't do (it simply multiplies by the matrix without translation).

Also, because of the divide by W, transforming vectors (as opposed to points) by a projection matrix is probably not what you actually want. If what you want is the screen-space vector between two points, you should transform and divide-by-W each point, then subtract them to get a screen-space vector. Otherwise the vector will likely be inaccurate.