Accessing Pawn Motion Controllers from C++

Have motion Controllers setup as components in my player pawn in Blueprint. Works great.

I would now like to access those from c++.

Tried to use the Initialise() methodology we used in Battle tank to pass references but get an error.
“DomePlayerController.h(20) : Unrecognized type ‘MotionControllerComponent’ - type must be a UCLASS, USTRUCT or UENUM”

Any ideas why this isn’t working?

The class is prefixed with a U, like all components. The full name is UMotionControllerComponent.

Going out on a limb here, but I would try running the UCLASS() macro before setting up the MotionControllerComponent class (your step 1).

Forward declarations should go before the class. His problem is he simply forgot the prefix :slight_smile:

Thanks Guys! That got it compiling! Sometimes it’s the simple things …

BUT the Initialize_Ctlrs routine doesn’t appear as a function in the Pawns BP editor event graph.

Is that because the Player Controller class is not a Component?

I tried replacing UCLASS() with UCLASS(ClassGroup = (Custom), meta = (BlueprintSpawnableComponent)) but that didn’t help.

Is the correct way to do this to:

  1. Create My own Motion Controller class
    -> add an Initialize routine that is Blueprint Callable
    -> Make the Motion Controller a Blueprint Spawnable Component

  2. Use My Motion Controller Component in the BP editor instead of the default Motion Controller Component
    In Event Graph: add initialize to pass references to C++

  3. Then from the Player Controller routine:
    Get reference to My Motion Controller component
    Use that reference to access the motion controllers?

Seems like a long way around, but also seems to make sense.

Any guidance?

You shouldn’t have to make it a spawnable component since it’s just your player controller… are you sure you’re using a reference to your custom player controller to try to add the event? Because you might not be able to if you’re just trying to add it from your pawn alone.

And also, in the first answer I was unaware you were intending to make your own motion controller class. Your way seems to be good.

Thanks Carson,

Yeah, I was trying to bypass making my own Motion Controller component, but it looks like that is the way to do it.

I’ll give it a shot.

Thanks for you help!

Hi Guys,

Found a completely different way to do it. Thought I would pass it along.

This is in my custom Player Controller - allows me to get references to BOTH VIVE Motion Controllers from my custom Player Controller without creating a new Motion Controller Component:

I need to delete MyMotionControlComponent and simply use the original at this point.

This is the web page I found it on.