x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

C++ Ai Controller: referencing BTrees and Blackboards

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++?

Product Version: UE 4.10
Tags:
more ▼

asked Nov 16 '15 at 06:00 PM in C++ Programming

avatar image

NegInfinity
99 13 17 29

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You could mark your BB/BT properties as "exposed on spawn", like so:

 UPROPERTY(BlueprintReadWrite, meta = (ExposeOnSpawn = true))
 UBehaviorTree* BehaviorTree;

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.

Cheers,

--mieszko

more ▼

answered Nov 16 '15 at 06:46 PM

avatar image

MieszkoZ STAFF
7.4k 225 57 415

avatar image NegInfinity Nov 16 '15 at 07:06 PM

Hi there.

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

avatar image MieszkoZ STAFF Nov 16 '15 at 09:11 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question