Download

Question about a Variable in the Behavior Tree

We have this variable in Behavior tree where we can set blackboard keys.
I am talking about making the AI. I watched a tutorial, but the tutor didn’t quite explain why we use this variable twice and what it does.
So my question is what does it do? WWhy do we set the variable to state in the behavior tree, when we already set value blackboard value in the blueprintbase serice?
I am not sure what the variable does. In the blueprint service I set it alrady to state and give it a new numerable value (combat)
Why is there this variable that needs to be set in behavior tree to state again?
I want to clarify this.

I guess I want to mention that, I could just copy and paste. But I am not a Chinese, I use my logic, and I want to understand. Thanks

In behavior Tree you tell it that “State This Blueprint” uses “State” variable from blackboard.
Then in blueprint you set value of variable that “State This Blueprint” points to.

One good practice with behavioral trees is naming all blackboard key variables with _Key suffix (or prefix), this way you see what that variable is for.
So you have “State” variable, I would name that blackboard key variable as “State_Key” not “State This Blueprint” which is confusing.

I see. So I guess I assumed it correctly, the Variable gets the value from blackboard, then in the blueprint from this variable this value will be set to something. Am I right?
But then why does the next node, the decoder, reads directly from blackboard and not from the variable? ![{AGY0_2JM$(_}T~D1@WG9Y.jpg|798x366
Who reads from the variable? What is the variable exactly for. Does this variable change the value in the Blackboard? Or just read from it?

OK. If I am not mistaken, the variable is there to change the value. In the behavior tree u link it to the blackboard value. Then in the Blueprint u set the value to something. This variable “state_key” does not only read but does changes to the blackboard.
Then the next node in the behavior tree reads directly from the blackboard.
Is that right? So basically the blueprint cant change the value in the blackboard without this variable for whatever reason. Am I right?
Tell me does the blueprint only reads from the variable or does changes to the value of the variable as well?

Thing is that Behavior tree has only one instance (there is single behavior tree for all AI that run same behavior tree). Then you have Blackboard which has copy of it for each AI that uses it.

This is why you cannot store anything in behavioral tree, or in blueprints that are used as nodes. They all will forget all variables, so all variables in those blueprints are local.
This is also why we have blackboard, it is asset that can keep our variables safe while behavioral tree calculates another AI state (And uses another copy of blackboard)

KEY types of variables are some kind of pointer or reference, they tell behavioral tree which blackboard variable should be used by that key. You bind those key variables to blackboard variables in those dropdown list in behavioral tree. Then after you bind them correctly you can read and save values to blackboard.

You also can think about blackboard as array. Then blackboard key would be index in that array. And then in behavior tree you set information that Key_whatever uses variable at index X.

I don’t understand “this is why u cannot store anything in behavior tree …”
Where was the explanation? I guess u mean everything is stored in several blackboards for each AI, and that’s the location where it’s supposed all to be stored. So that#s just how the system works, but what u said was no explanation to my question.

But I know that these variables are linked to the values in the blackboards, which will be set in blueprint.

I tried to explain how blackboard works with behavioral tree.

On picture of that blueprint you only set value in blackboard. That node does not set value of key variable it sets value in blackboard for variable that key is pointing to.

And you cannot store variables in behavioral tree they are forgotten on next AI tick. Blackboard is used to store values for behavioral tree.

I understood the general idea long ago. The blackboard stores. The behavior tree acts. Was just confused with the variable. So like I said the variable is linked to the blackboard, and when u change value in the blueprint via the "set blackboard enum"node it changes the value in the blackboard over the variable. That’s how I understand it.