Get MSBuild error when trying to forward declare UBehaviorTree & UBehaviorTreeComponent

Im trying to create a AIController in Unreal Engine 5 should be the same in UE4. But I cannot access UBehaviorTree class or UBehaviorTreeComponent.
I dont have alot of knowledge about BehaviorTrees in Unreal but I know that I need the Controller to access the Tree so I can posses a character class.
This is the .h file so far:

This is the .cpp file:

Error message that I am getting:

If I comment the private section and stop forward declaring the two classes I don’t get any errors so it has something to do with that somehow.

Thankful for any suggestions / help!

Maybe this will help:

.h
#include "Runtime/AIModule/Classes/BehaviorTree/BehaviorTreeComponent.h"
UCLASS()
class AMyController : public AAIController
{
    GENERATED_BODY()

public:
    :

protected:

    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = AI, meta = (AllowPrivateAccess = "true"))
    UBlackboardComponent* BlackboardComp;

    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = AI, meta = (AllowPrivateAccess = "true"))
    UBehaviorTreeComponent* BehaviorTreeComp;

Hm yeah maybe it will but I dont se why I cant just forward declare them. Will try it out thx.

Update : It didnt do anything unfortunatly

Forward declaration is fine, try adding #include "BehaviorTree/BehaviorTreeComponent.h" and #include "BehaviorTree/BlackboardComponent.h" to your cpp

I am not using UE5 and I cannot create a test project at the moment to try. As @SolidGasStudios stated forward declarations are fine, I use them all the time as well as class . If your problem goes away when commenting out the private code, try commenting out the UPROPERTY lines and see if that works. That is a UHT/UBT issue.

Okay so it worked by removing the UPROPERTY lines.
But what should I use then if i want to access them?

Thx @anonymous_user_1267f45c

Thx I have them included in the cpp I thought it could have been that at first, but it wasnt.

I noticed you are using EditInstanceOnly, try omitting that or try my version and see if that helps.

Sorry, I think it may be the spelling of EditInstanceOnly, the “n” is missing.

what should i use instead of EditInstanceOnly, im quite new to Unreal Engine overall

Hm i tried adding that ‘n’ and un commenting UPROPERTY but it still gives me that error message

@HugBeg2000 you may be missing the “n” before the “ce” from EditInstanceOnly

What about using:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = AI, meta = (AllowPrivateAccess = "true"))

That worked, whats the difference?

I don’t know why your version failed and I don’t have time to investigate it. But I am happy it worked for you :slight_smile:

thx for all the help and your time

1 Like