In the blueprint of my NPC I have added the AI Perception component, configured the Sight sense in there and added an On Target Perception Updated event to the Event Graph.
I pass the Actor sensed to a custom function. Everything compiles fine but when the Actor (my playable character) is actually sensed during runtime the game crashes with an EXCEPTION_ACCESS_VIOLATION. It happens whenever I try to do anything with the Actor passed to my function.
void AEnemy::Chase(AActor* targetPawn)
{
auto animInst = GetMesh()->GetAnimInstance();
auto enemyAnimInst = Cast<UEnemyAnimInstance>(animInst);
if (targetPawn != nullptr && enemyAnimInst->State == EEnemyState::Locomotion)
{
auto enemyController = Cast<AEnemyController>(GetController());
enemyController->MoveToActor(targetPawn, 90.0f);
}
_chasedTarget = targetPawn;
}
As is, it will crash when calling MoveToActor.
Btw, I have tried the same with the PawnSensingComponent first and get the same error. I’m following the tutorial from this book:
Amazon.com: Unreal Engine 5 Game Development with C++ Scripting: Become a professional game developer and create fully functional, high-quality games: 9781804613931: ZHENYU GEORGE LI: Books