I'm trying to use external behavior trees as building blocks that I can easily slot in and use for different characters with complex behavior - I don't want to rewrite "Move over there and pick up an object" dozens of times. So I frequently call external behaviors and set a simply-named variable like "TargetObject".
However, I've discovered that if I set TargetObject on Behavior Tree Reference A and then set a variable named TargetObject on Behavior Tree Reference B that pops up later, B will end up with the value I set for A. This seems very bizarre to me as I would expect that setting it the second time would override the variable and instead it does nothing. Changing the name of the variable in tree B to "TargetObjecto" makes it work (at least when you're not reusing the same trees), but this is not a viable solution for me.
Note that I do not have a TargetObject variable in my main tree. In fact I discovered that if I set up a variable named TargetObject in the main tree and leave it at null then setting the variable on the external tree through the BTR task won't do anything, it will just remain null!
My conclusion is that setting variables through the BTR task only works if you never have another variable with the same name in the expanded tree. This seems like a nasty bug and it's certainly stopping my plans cold! Let me know if you need any other info from me, but it should be pretty straightforward to set up.
However, I've discovered that if I set TargetObject on Behavior Tree Reference A and then set a variable named TargetObject on Behavior Tree Reference B that pops up later, B will end up with the value I set for A. This seems very bizarre to me as I would expect that setting it the second time would override the variable and instead it does nothing. Changing the name of the variable in tree B to "TargetObjecto" makes it work (at least when you're not reusing the same trees), but this is not a viable solution for me.
Note that I do not have a TargetObject variable in my main tree. In fact I discovered that if I set up a variable named TargetObject in the main tree and leave it at null then setting the variable on the external tree through the BTR task won't do anything, it will just remain null!
My conclusion is that setting variables through the BTR task only works if you never have another variable with the same name in the expanded tree. This seems like a nasty bug and it's certainly stopping my plans cold! Let me know if you need any other info from me, but it should be pretty straightforward to set up.
Last edited: