How to access Blueprint Components from C++

Hi Guys,

Anyone know of a way to access a Blueprint component from a C++ PlayerController?

I have a Blueprint with a Pawn as the parent.

Would like to access the motion controller component in that blueprint from PlayerController.cpp.

Seems like I should be able to:
auto MotionControllerLocation = GetControlledPawn()->GetController()->GetActorLocation();

but that doesn’t work…

Do I need to create a C++ class for my pawn and have that as the parent to my Blueprint?

Thanks for any insight …

A motion controller isn’t a controller in the sense of the GetController() method, that’s for the AController object that owns the pawn. Their names are just ambiguous. There’s a few ways to accomplish what you’re trying to do that are outlined in the course, including the CreateDefaultSubobject route (the functionality gets put onto the parent class, so you would need to make one), and the “initialize” method technique (passing the components to the parent on BeginPlay, you would also need a parent class).

Awesome - I’ll take a look. Thanks!

Privacy & Terms