Download

Referencing a Behavior Tree in C++

I’m trying to set my behavior tree in my AI Controller using C++ with the following code:

ShooterController.h



UPROPERTY( )
class UBehaviorTree* BehaviorTree;


ShooterController.cpp



static ConstructorHelpers::FClassFinder< UBehaviorTree > ShooterBehaviorTreeReference(
	TEXT( "BehaviorTree'/Game/AI/ShooterBehaviorTree.ShooterBehaviorTree_C'" ) );

BehaviorTree = ShooterBehaviorTreeReference.Class.GetDefaultObject( );


The problem is that the Constructor Helper is failing to find the Behavior Tree Blueprint. I get the following error pop-up when I start the editor.



Default Property warnings and errors:
Error: CDO Constructor (VShooterController): Failed to find /Game/AI/ShooterBehaviorTree.ShooterBehaviorTree_C


Am I using the FClassFinder incorrectly?

OK, I got the error to stop appearing by switching the FClassFinder to a FObjectFinder.

I’m assuming you need to choose which one to use based on the base class of the thing you are trying to reference?

I also had to remove the ‘_C’ from the name of the resource, why do you use it for some but not others? It is only ‘classes’ and not ‘objects’?

Yep. You are looking for an instance of an object spawned in level, not a base class…