UE4 gets stuck when opening if I use this code but it opens fine if I disable it.
static ConstructorHelpers::FObjectFinder<UBehaviorTree> BT(TEXT("BehaviorTree'/Game/Blueprints/Turret_BT.Turret_BT'"));
It also runs fine if I compile it after opening the editor.
My header:
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "Perception/AIPerceptionComponent.h"
#include "TurretController.generated.h"
UCLASS()
class CPPPROJECT1_API ATurretController : public AAIController
{
GENERATED_BODY()
public:
ATurretController();
virtual void BeginPlay() override;
UPROPERTY(BlueprintReadWrite, VisibleAnywhere)
UAIPerceptionComponent* PerceptionComp;
UFUNCTION()
virtual void OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus);
};
My .cpp:
#include "TurretController.h"
#include "BehaviorTree/BehaviorTree.h"
ATurretController::ATurretController() {
PerceptionComp = CreateDefaultSubobject<UAIPerceptionComponent>(FName("AIPerceptionComponent"));
PerceptionComp->OnTargetPerceptionUpdated.AddDynamic(this, &ATurretController::OnTargetPerceptionUpdated);
static ConstructorHelpers::FObjectFinder<UBehaviorTree> BT(TEXT("BehaviorTree'/Game/Blueprints/Turret_BT.Turret_BT'"));
}
void ATurretController::BeginPlay() {
Super::BeginPlay();
}
void ATurretController::OnTargetPerceptionUpdated(AActor* Actor, FAIStimulus Stimulus) {
}
I got the reference to the object from the editor and it works fine with other objects.
Never mind, there was no problem with the code. The problem was with the content inside of the BehaviorTree.