UE4 gets stuck at 75% when using ConstructorHelpers

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.

Hi,

The following code works for me on 4.26.2:

static ConstructorHelpers::FObjectFinder<UBehaviorTree> BTObject(TEXT("/Game/Hero/Animals/CompanionFox/BehaviorTree/BT_FoxCompanion.BT_FoxCompanion"));
if(BTObject.Succeeded())
{
    UE_LOG(LogTemp, Warning, TEXT(__FUNCTION__ " | FOUND BEHAVIOR TREE"));
}

Using this code, I get the UE_LOG printed in my output log:

352090-log.png

I believe in your case, instead of this:

static ConstructorHelpers::FObjectFinder<UBehaviorTree> BT(TEXT("BehaviorTree'/Game/Blueprints/Turret_BT.Turret_BT'"));

You should write this:

static ConstructorHelpers::FObjectFinder<UBehaviorTree> BT(TEXT("/Game/Blueprints/Turret_BT.Turret_BT"));

I hope this helps, and good luck :slight_smile:

Do you get any more information than it just being stuck on 75%? Any kind of CDO warning?

I wrote like this the first time and it didn’t work. So someone told me to get the reference to the object from the editor itself that’s why I wrote it like that.

352103-screenshot-2021-11-13-190022.png

But anyway, thank you for taking your time to help me :slight_smile:

Nope didn’t get any kind of errors. But it works if I enable the code and compile it after I open the editor and play the game.

Never mind, I fixed it! There was no problem with the code. The problem was with the content in the BehaviorTree.