Hi folks,
I have an issue where I’m adding an UAIPerceptionComponent (code will come soon) to my AIController…
I created a BP from it and I see it as inherited as expected… But… When I want to add senses it won’t let me… It will let me to select the dominant sense but not add senses…
I looked at https://answers.unrealengine.com/questions/602376/perception-component-added-in-c-wont-allow-senses.html which is the most relevant thing I could find and unfortunately it didn’t help…
This is the header file:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "EnemyAIControllerBase.generated.h"
/**
*
*/
UCLASS()
class CODENAMEUNKNOWN_API AEnemyAIControllerBase : public AAIController
{
GENERATED_BODY()
public:
AEnemyAIControllerBase();
UFUNCTION(BlueprintCallable)
class UBlackboardComponent* GetBlackboardComponent() { return BlackboardComponent; }
protected:
virtual void BeginPlay() override;
virtual void OnPossess(APawn* InPawn) override;
private:
UPROPERTY(Category = "AI", EditDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UBehaviorTreeComponent* BehaviorTreeComponent;
UPROPERTY(Category = "AI", EditDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UBlackboardComponent* BlackboardComponent;
UPROPERTY(Category = "AI", EditDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UBehaviorTree* BehaviorTree;
UPROPERTY(Category = "AI", EditDefaultsOnly, BlueprintReadWrite, meta = (AllowPrivateAccess = "true"))
class UAIPerceptionComponent* AIPerceptionComponent;
};
This is the CPP file:
// Fill out your copyright notice in the Description page of Project Settings.
#include "EnemyAIControllerBase.h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "Perception/AIPerceptionComponent.h"
AEnemyAIControllerBase::AEnemyAIControllerBase()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
BehaviorTree = CreateDefaultSubobject<UBehaviorTree>(TEXT("Behavior Tree"));
BlackboardComponent = CreateDefaultSubobject<UBlackboardComponent>(TEXT("Blackboard Component"));
BehaviorTreeComponent = CreateDefaultSubobject<UBehaviorTreeComponent>(TEXT("Behavior Tree Component"));
AIPerceptionComponent = CreateDefaultSubobject<UAIPerceptionComponent>(TEXT("Perception Component"));
SetPerceptionComponent(*AIPerceptionComponent);
AIPerceptionComponent->bEditableWhenInherited = true;
}
void AEnemyAIControllerBase::BeginPlay()
{
Super::BeginPlay();
if (BehaviorTree == nullptr) {
return;
}
RunBehaviorTree(BehaviorTree);
BehaviorTreeComponent->StartTree(*BehaviorTree, EBTExecutionMode::Looped);
}
void AEnemyAIControllerBase::OnPossess(APawn* OnPossess)
{
Super::OnPossess(OnPossess);
if (BlackboardComponent == nullptr || BehaviorTree == nullptr) {
return;
}
UBlackboardData* BlackboardAsset = BehaviorTree->GetBlackboardAsset();
if (BlackboardAsset != nullptr) {
BlackboardComponent->InitializeBlackboard(*BlackboardAsset);
}
}
Would appreciate any help here please, I’m sure I’m missing something dumb, but what? or is it a bug?
I get the feeling that Epic Games are hinting me that I’m not using this as they wanted me to use it
My goal in the end is to be able to add the AIPerceptionComponent in the code and configure it in BP…
EDIT:
I also tried providing UPROPERTY for the sight sense config and assigning it to the AIPerceptionComponent but it also didn’t show it in the array…
EDIT #2:
As discussed in the comments with TheKaosSpectrum, there is a workaround here, it is just to add the AIPerceptionComponent directly in the BP and then when using GetPerceptionComponent() function which is part of AIController it will find it and return it… Or… Go full blown C++ like in the link above…
The Main Question:
Why is it working when I add it in the BP but not when it’s inherited because I add it in the C++ code? :
This is more of me being curious now than actually blocked…
Thanks in advance.