简体   繁体   English

UE4 在使用 ConstructorHelpers 时卡在 75%

[英]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.如果我使用此代码,UE4 在打开时会卡住,但如果我禁用它,它会打开。

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:我的.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.问题出在 BehaviorTree 内部的内容上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM