How do I reference an Instance of another class in UE4?

Hey,

I am currently trying to write an AI of my own for the Vehicle template of UE4.
The Vehicle has it’s own funtions that move it through the scene and give it a bit of realism.
I would like to trigger these functions on the instanced pawn from a Blueprint function library in c++.

How would I be able to reference the cars instance so that I could access functions like MoveForward etc.?

I’m not familiar with the Vehicle template, but I assume that it is a pawn that the PlayerController possesses? If that’s the case, you can simply do something like this:


YourVehicleClass* MyVehicle = UGameplayStatics::GetPlayerController(this, 0)->GetPawn<YourVehicleClass>()

If I read it correctly it will store a pointer to to Pawn of the Character Controller which can be found using the GamePlayStatics.
I am not 100% certain that the Pawn is controlled by the PlayerController but it’s common practice so it would only make sense for the peeps at Unreal Engine to implement it that way.

Unfortunately I am still getting an error:
Error (active) E0167 argument of type “Vehicle AI *” is incompatible with parameter of type “const UObject *” , highlighting the “this” parameter for GetPlayerController.

To give some further context:
I am using a blueprint function library to communicate between blueprint and a c++ class for the AI.
Therefore the function library creates an instance of the AI class and can call functions on that class and change the database which is represented by another class.
The issue really is triggering functions of the Pawn Class on the spawned instance of the car from there ^^

I am currently trying to execute the function you gave me from the AI c++ class.

Do you have any ideas on how to fix this or an alternative approach?