I’m trying to write AI controller in C++. The controller is supposed to access blackboard and run behavior tree.
The problem is, I’m not sure how am I supposed to reference which behavior tree/blackboard the controller is supposed to use. C++ controller class pretty much exists in vacuum and doesn’t expose any of its properties anywhere. I could, of course, hardcode path to relevant assets into C++ code, but that obviously is not the right way to do it.
So, how am I supposed to specify which Blackboard/Behavior Tree should be used by AI controller, when AI controller is written in C++?
You could mark your BB/BT properties as “exposed on spawn”, like so:
UPROPERTY(BlueprintReadWrite, meta = (ExposeOnSpawn = true))
Those properties will get exposed as input pins to BP’s
SpawnActor. Down side of this approach is that you’ll need to spawn AI controllers manually.
Or you can make those properties “config variables” by adding
config tak to UPROPERTY markup. Downside here is all controllers will be using the same asset.
What I normally do is I’m hosting BT property on pawns, so that when AI controller possesses a pawn it used the BT asset associated with given pawn class/instance.
I was talking about turning BTrees/BBoards into editable properties in editor.
After tinkinering with this, it looks like the “right” way to do it is to have UBehaviorTree* and UBlackboardData* available as properties (UPROPERTY) somewhere (either within pawn or within controller subclass), and then in DerivedAIController::BeginPlay call UseBlackboard for blackboard and create UBehaviorTreeComponent and use it to actually run referenced tree.
That about right? Or am I missing anything?
P.S. DerivedAiController denotes any subclass of AAIController
That’s why I said I usually make BT asset a property in Pawn class. This way you’ll have it editable via the editor. You don’t have to specify a blackboard asset yourself, AI will use the one specified in BT’s root node.