C++ GetControlledPawn identifier not found

Hello, as the title states, The GetControlledPawn() function is undefined. I’m pretty new to this and decided I’d first start by setting up a custom pawn and player controller. In many examples I’ve seen they use GetControlledPawn() to get the pawn and setup input in the controller. I have included the header file #include “GameFramework/Controller.h” and yet it is still undefined.

Much help would be appreciated. As I stated I’m new, so if I’m going about this the wrong way or something else looks off please let me know.

I think you need to call GetPawn() instead. I would also recommend moving that code to the possess function, which you will need to override. I do not think the code will work as you have posted it because you need to call GetPawn after the pawn is possessed. Here is an example you can try.

// Header file
// Forward declare APawn at the top of your header somewhere
    class APawn;
    // Override possess function
	virtual void Possess( APawn* InPawn) override;

// cpp file

void AMyPlayerController::Possess(APawn* InPawn)
{
	Super::Possess(InPawn);
        GetPawn();
}