HugBeg2000
(HugBeg2000)
November 18, 2021, 9:33am
1
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;
HugBeg2000
(HugBeg2000)
November 18, 2021, 3:40pm
3
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.
HugBeg2000
(HugBeg2000)
November 18, 2021, 3:56pm
6
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
HugBeg2000
(HugBeg2000)
November 18, 2021, 3:58pm
7
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.
HugBeg2000
(HugBeg2000)
November 18, 2021, 3:59pm
10
what should i use instead of EditInstanceOnly, im quite new to Unreal Engine overall
HugBeg2000
(HugBeg2000)
November 18, 2021, 4:01pm
11
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"))
HugBeg2000
(HugBeg2000)
November 18, 2021, 4:03pm
14
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
HugBeg2000
(HugBeg2000)
November 18, 2021, 4:07pm
16
thx for all the help and your time
1 Like