I have a behavior I’m working on in C++ that’s used for controlling AI Vehicle Input. I originally had it mocked up in Blueprint, but I’ve hit a bit of a snag implementing it on the code side.
In my blueprint, the task’s “Received Execute” node passes the Owner, which represents the AIController. I used the AIController to get the Controlled pawn, so I can later get its Vehicle Movement component, etc.
For the life of me, though, I cannot find a way to actually get the current AIController from a BTTaskNode. In ExecuteTask(), you have a pointer to a UBehaviorTreeComponent, so I’ve been trying the following:
UWheeledVehicleMovementComponent* UWagonDriveTask::GetVehicleMovementComponent(class UBehaviorTreeComponent* OwnerComp)
{
AAIController* pController = Cast<AAIController>(OwnerComp->GetOwner());
if (pController)
{
APawn* pPawn = pController->GetPawn();
if (pPawn)
{
return Cast<UWheeledVehicleMovementComponent>(pPawn->GetComponentByClass(TSubclassOf<UWheeledVehicleMovementComponent>()));
}
}
return NULL;
}
But, it seems to crash on actually getting the Component. Any ideas?