So I’ve already switched to using APlayerController::GetHitResultUnderCursor, but for my first attempt at getting the mouse position in 3D, I used APlayerController::DeprojectMousePositionToWorld (and DeprojectScreenPositionToWorld with the results of APlayerController::GetMousePosition passed as parameters) as a starting point for a trace.
This, however, does not return anything close to the expected values at all.
For example, - YouTube uses the code below in the possessed pawn’s tick.
(myController is a cached (APlayerController*)GetController() that has bShowMouseCursor, bEnableClickEvents and bEnableMouseOverEvents set to true)
FVector worldLoc, worldDir;
myController->DeprojectMousePositionToWorld(worldLoc, worldDir);
FString testString = "loc " + worldLoc.ToString() + " dir " + worldDir.ToString();
GEngine->AddOnScreenDebugMessage(-1, 0.1f, FColor::Red, testString);
The values DeprojectMousePositionToWorld returns are the pawn location + ((-3,3), (-10,10),-10) instead of ((-270,270),(-130,1200), pawnLoc.Z-10), so… what’s going on?
The worst part is that the answerhub and the wider internet is full of people saying DeprojectMousePositionToWorld was what they needed with exactly the same code.