Is it possible to Convert Mouse Position to World Space without a Player Controller?

I’m currently trying to a make an actor in an Editor Preview Scene rotate towards a position the user clicks on. This is fairly simple while in game and PIE as Player Controllers have many useful functions such as Get Hit Result Under Cursor and Deproject Screen Position To World to go about this. However, outside of PIE and runtime there is no Player Controller to convert mouse position to world space.

All of Unreal’s functionality to do this appears to rely on a Player Controller, so is what I’m looking to accomplish impossible or am I going about this incorrectly?

auto client = (FLevelEditorViewportClient*)GEditor->GetActiveViewport()->GetClient();
if (client != nullptr) {
}

You can try doing that to get the viewport and the “client.” If you look up FLevelEditorViewportClient you can see it has some functions that might be useful. The most relevant one is probably GetCursorWorldLocationFromMousePos.

Thank you for that direction! I wasn’t working in a LevelEditorViewportClient and completely missed that function. It was helpful to see how UE4 was doing it!

In the end I calculated the SceneView and used DeprojectFVector2D to get WorldPosition and WorldDirection from a Click Position.

FVector2D ScreenPosition(Click.GetClickPos());
FVector WorldPosition;
FVector WorldDirection;
    			
FSceneViewFamilyContext ViewFamily(FSceneViewFamily::ConstructionValues(
    ViewportClient->Viewport,
    ViewportClient->GetScene(),
    ViewportClient->EngineShowFlags));
    
FSceneView* View = ViewportClient->CalcSceneView(&ViewFamily);

View->DeprojectFVector2D(ScreenPosition, /*out*/ WorldPosition, /*out*/ WorldDirection);

And is it possible to do this in edit mode (not runtime)? For a plugin, for example?