How to add PlayerController function GetHitResultAtScreenPosition to a Pawn class

I’m trying to use the GetHitResultAtScreenPosition for a project in a Pawn class, but adding the “GameFramework/PlayerController.h” doesn’t work in the cpp file. I’ve also tried remaking the function but I’ve gotten dll errors.

Is there any way that I can call the function in a Pawn class?

GetHitResultAtScreenPosition is a method of the APlayerController class. Assuming your pawn is possessed, try:

MyPawn
    ->GetController<APlayerController>()
    ->GetHitResultAtScreenPosition( /* ... */ )
2 Likes

So like calling the function by using the player controller right?

Yes. You should first make sure the Pawn actually has a valid Player Controller, and assuming it does, call the method on the Player Controller.

I would like to add (after an hour of bumbling around) that the -> should be :: to access the class functions. The second one (being a pointer return) should be a ->.

No wait now I’m getting non-static method issues.
Edit 1: Nevermind I forgot to put the APawn:: in front of the function name.

I’ll write this down since Unreal Forums won’t allow for multiple solutions. (Thank you x157 for the help)

MyPawn
    ::GetController<APlayerController>()
    ->GetHitResultAtScreenPosition( /* ... */ )
1 Like