diff --git a/Source/vampires/VampireAIController.cpp b/Source/vampires/VampireAIController.cpp index baf4afe..a89f75e 100644 --- a/Source/vampires/VampireAIController.cpp +++ b/Source/vampires/VampireAIController.cpp @@ -36,11 +36,9 @@ void AVampireAIController::Tick(float DeltaTime) { Super::Tick(DeltaTime); - if (AVampireCharacter* Player = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0))) + if (PlayerCharacter) { - Blackboard->SetValueAsObject("Player", Player); - auto location = Player->GetActorLocation(); - Blackboard->SetValueAsVector("PlayerLocation", location); + Blackboard->SetValueAsVector("PlayerLocation", PlayerCharacter->GetActorLocation()); } } @@ -54,11 +52,18 @@ void AVampireAIController::OnPossess(APawn* InPawn) EnemyCharacter->GetHealthComponent()->OnDamaged.AddDynamic(this, &AVampireAIController::OnDamaged); EnemyCharacter->GetHealthComponent()->OnDeath.AddDynamic(this, &AVampireAIController::OnDeath); + PlayerCharacter = UGameplayStatics::GetPlayerCharacter(GetWorld(), 0); + if (UBehaviorTree* bt = EnemyCharacter->GetBehaviorTree()) { Blackboard->InitializeBlackboard(*bt->BlackboardAsset); BehaviorTree->StartTree(*bt); Blackboard->SetValueAsObject("SelfActor", EnemyCharacter); + + if (PlayerCharacter) + { + Blackboard->SetValueAsObject("Player", PlayerCharacter); + } } } diff --git a/Source/vampires/VampireAIController.h b/Source/vampires/VampireAIController.h index 80c8327..1a3f571 100644 --- a/Source/vampires/VampireAIController.h +++ b/Source/vampires/VampireAIController.h @@ -22,7 +22,7 @@ class VAMPIRES_API AVampireAIController : public AAIController UBehaviorTreeComponent* BehaviorTree; - APlayerCharacter* PlayerCharacter; + ACharacter* PlayerCharacter; AEnemyCharacter* EnemyCharacter;