Behavior Tree Decorator/Selector Only Runs the First Decorator

Yes okay, I just noticed that the BBData is null. I’ve changed the trustrank string to be 0 and now the first one is never true, either. It doesn’t look like I’m able to print the key, I can’t connect the two nodes

Ok… let’s take a step back and look at all of the variables and do some renaming.
“TrustRank” needs more specificity, because it’s a shared name in too many places.

Blackboard: This has the permanent variables. Name this one BB_TrustRank.

Decorator: This has variables that are kept within the decorator. You need three here: D_RankToCheck, which should be public and set outside because this is what you are checking against. Then KEEP your TrustRank variable but make it private- this should only be used to set the D_TrustRank value.

BBKey: Change this to also tell what value you’re trying to get. Name this one BBKey_TrustRank.

The Blackboard Key not retrieving anything, returning null- that means the BB_TrustRank is not set. You’re setting the TrustRank value on the Decorator- but because it’s named the same as the Blackboard value it’s getting confusing- those are not the same variable. The BBKey_TrustRank is pulling from here:

I have a good feeling this is not set:

Let’s just… Put the things where they need to go. Putting all of this on a decorator is not only confusing, it’s terribly non-performant nor reusable.

First: A BTTask:

This makes all of the checking and valuations have to run only ONCE as opposed to 5x so that’s a 5x improvement right there. This will set the trustrank as it needs to be set on the BB for checking.
Also you can reduce the amount of checks needed by removing the ceiling checks, if they don’t pass the floor checks, it’s the same thing so you’re just checking 2x more than needed. :slight_smile:

Next: A BTDecorator:


Decorators are typically this simple, however you can have a lot of checks going on but the main thing is to return TRUE/FALSE. Make sure you use “Perform Condition Check”!

Lastly: The BT/BB:

You run the task before asking which rank you’re looking for. :slight_smile:

This is your more typical use cases for these things and what I’m far more familiar with- not all of this is best practices, as the 6 options could be changed into a single task that checks the value and gets a certain value from a DataTable based on the trustrank.

Whew. Hope this helps with your thing! I couldn’t 1:1 as I don’t have everything you do but I figured going back and forth asking for one thing at a time was getting to be tedious.

Edit:
You don’t have to use a custom decorator. You can just use the built in “Blackboard” option:

1 Like

This was extremely helpful, its so useful to know how to optimize these things. I’ve replicated what you’ve come up with (thank you so much for giving the visuals, by the way, I know that must’ve taken a minute and it’s super helpful) and I’m running into an issue of the BB key is still printing out to be unchanged after it’s meant to change.
The only part I’m not sure if I understand is on the screenshot of the BTTask, the comment that says “Make sure to set this on the behavior tree!” I think I did but I wasn’t sure at first so that could be the problem. (I also kept using my sequence nodes to attach the decorators to, because it seems to function the same either way and I’d like to use the sequences in the future.)

(Also, I’ve been using video format because it displays everything easier in my opinion, but let me know if you find screenshots or something else easier to look over because I know it can be hard to pause and look at everything. I also found a website to send BPs through if that would help)

So before getting too far into analyzing, I looked and noticed that nearly everything was the same… Except you didn’t change the STRING variable into an Int. “Set Value As” won’t work if the values don’t match. BT’s can’t say no to programming that way since their values are generated at runtime and tasks/decos/services are meant for reuse across multiple BTs so it doesn’t check for errors like this. :slight_smile: A string can’t == an int. If it’s only ever going to be a number, just make it an int, and if it can have decimals make it a float and change it to set value as float.

1 Like

Can’t believe I missed that!! I’m so ecstatic, it’s working now. Thank you so much for all of your help!

1 Like

You’re very welcome! Don’t forget to select something as the answer so the thread closes! :slight_smile:

1 Like