Variable Synchronizer not syncing game object fields

xxchester

New member
I have 2 variables setup in my behavior tree, isTireScreeching and isBraking:
1650998264344.png
On my action I can see both of these fields getting updated when the action is running. However in my external mono behaviors while trying to access them, the value is always false via the tree lookup:
Code:
 bool isBraking =
                ((SharedBool)movementTree.GetVariable(Constants.KEY_IS_BRAKING)).Value;

Or via the Variable Synchronizer which looks to be a lot cleaner and ideal.
1650998374025.png

Any idea's?


EDIT:
I just noticed that, I have the values assigned to the variables in the inspector for my action, but when I run the game, these change back to check boxes, so it seems like the reference is getting broken?
1650999478886.png

How do I fix this?
 
Last edited:
The Variable Synchronizer is being deprecated so I do not recommend that you use that. You should instead use property binding:

 
Forgive me, I've read that variables section a few times and couldn't (and can't) get it to work for me, specifically the section about accessing variables from outside a Task object.

I can see the variables being set in the behavior designer's Inspector when I click on my action, but I cannot access the values via code. I have this code:
Code:
 var isScreeching =
                ((SharedBool)movementTree.GetVariable(Constants.KEY_IS_SCREECHING));
just like in the example but mine is always false unless I set it via script. What am I doing wrong here?

Maybe I am misunderstanding how this all works. I am setting the value of the property within my Action. Then I want to access the variable via my script. I have confirmed the action is setting the property and the Inspector in behavior tree also confirms this. However, the variable tab never updates even though I am mapping the variables.
1651066569951.png
I do see when I run the behavior though, the bools change back to check boxes, is this expected?
1651066777389.png
I am really lost here.

EDIT:
Here is the constants incase you were thinking it's a typo:
1651066973783.png
 
Last edited:
Are you setting the bool variables outside the task? That's the only thing that I can think of why the variable would switch to a non-shared status. When you set the bool variable you will want to ensure you just set the value and not the entire variable.

I have attached a small repro scene which shows how property mapping works. It also sets the value via script.
 

Attachments

  • BoolMapping.unitypackage
    3.4 KB · Views: 4
Bingo that was it, I was assigning the variable directly, not the value property. Strange that this is allowed when it breaks it.

Regardless, thanks for your support and great tool!
 
Last edited:
Top