Why isn't UBehaviorTree recognized as an identifier?

Hi HInoue,

In addition to the include directive that Moss mentioned, you should also make sure to add "AIModule" as a dependency in your project’s Build.cs file.

I’m trying to make a pointer to an object of type behavior tree, so I can change an NPC’s behavior at runtime by making it switch to using whatever tree I designate. I added #includes for BehaviorTree/BehaviorTreeComponent.h and BehaviorTree/BlackboardComponent.h , and tried creating my variable:

UPROPERTY(EditAnywhere)
UBehaviorTree* testTreePtr;

The contextual drop-down worked and had an entry for UBehaviorTree, so I know it’s a known type, but when I try to compile it throws an error, " error C3861: ‘Z_Construct_UClass_UBehaviorTree’: identifier not found". This makes me think that UBehaviorTree isn’t recognized as a valid data type, but the properly-formatted includes and its presence in the contextual prompt makes me assume the compiler likes it- am I doing something obviously wrong?

Try adding the following include:

#include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTree.h"

Hmm, even with the edition of BehaviorTree.h as a third include, it has the same “identifier not found” error.

That does the trick, thank you!

This is the logical path to follow if I need to set trees in code, right? I don’t like creating unnecessary dependencies, especially for small things like plug & play behavior changes.

That sounds like it should work fine. You have a couple options when it comes to changing AI behavior at runtime. The first, which you suggested, would be to actually change out the Behavior Tree that the AI is using. The second would be to have a “master” Behavior Tree that selects a Behavior Tree to run based on some condition (most likely a custom enum) set in the code. Both results should be essentially the same.