What is the best way to get and store references for use in a Behavior Tree?

Hello. I am wondering the best way to get and store references to characters/objects in a behavior tree. I suppose I could either grab them in the AI Controller or Task and assign them. But my question then is… how do I retrieve the reference?

Or is it more efficient to just cast for references every time in each task? There is the node “Get Blackboard value as object” but I can’t assign it to a variable of the object type I need it to be.

Hi, just a tip: for the blackboard Object, use the dropdown to specify the actual type, e.g. your own actor blueprint etc…

grafik

Yes but how do I pull the reference and use it on a task like so
Capture

Get Blackboard Value as Actor, or any other supported type to get a value from a blackboard key

If your variable is a specific type, then you need to cast. As a QOL tip, in the editor preferences you can find the option to auto cast connections, so if you drag from the return pin of the get blackboard value as object/actor and try to connect that to your variable, then it will automatically add a cast node in between

image


These functions are available inside BT tasks, services and decorators

You could do something like this, in case you need to store the value in a variable:

But actually, this makes only sense, if for example you want to do something with tick, so not doing the get from blackboard and casting on each tick…

Simply ignore all those connections going up, I just inserted this into an existing task for screenshot