Hello, I am learning how to make behavior trees now and I bumped into an issue. I have a custom script on my tree owner, with a List field of a custom type on it. I set up a binary selector where I’d like to check if this list equals to one of those custom type value. Type = Idle, Target Position = Vector3(0,0,0)
My binary selector is set up as shown in the attached image, but even when my list in the tree owner’s script contains the element I’m looking for (see bottom part of my screenshot), the FALSE branch executes.
What am I missing in this concept here? I’m sure it’s on me, I just need a little help. 🙂
When comparing lists in c# it is done so by reference and not the values it contains. The values to not matter, and the comparison is comparing if the two lists are the same object reference. Thus your setup is not really correct 🙂
To check if a lists contains some element, you will need to use the “List Contains Element” condition. It is still tricky though because even the elements within are compared by reference if your elements (Command) are a “class” and by value only if they are a “struct”.
Thus is your Command is a struct, you will have to:
Store the list in a variable (Get Field).
Use the List Contains Element condition, targeting that stored list.
If your Command is a class, then it really gets far more complex and in that case a custom condition would probably be much better in that case.
Let me know if that works for you.
Thanks.
(PS: Please remember to post NodeCanvas questions in the NodeCanvas forums 🙂 )