Download

Behavior Tree Event-Based Decorator

I have a question regarding Decorators.
I need an event-based decorator that is triggered based on some event in the world.
e.g. When an Alien lands, all minions stop what they are doing and run.

As far as I know, the current options don’t seem to facilitate this:
If I mark a decorator’s Flow Control as None, then it is only evaluated when the node is evaluated which can be quite a while based on the tasks.
e.g. Minions dont check to see if alien lands unless they are done whatever they are doing.

If I mark a decorator’s Flow Control as Observer Aborts, then it is evaluated every tick of the tree … e.g. polling the condition. This is the correct behavior, and when it triggers it instantly cancels behavior. e.g. Minions are constantly checking some state to see if the alien lands. But this seems ineffecient and scales poorly with the number of agents?

A service does not appear to work in this instance either, as it is constantly polling as well.

Ideally, I would like an Event-based Decorator condition. E.g. Some other Game Actor could trigger an event which causes the condition to trigger.

When the decorator is first executed, it could bind an event to a dispatcher.
Then if the event is triggered, it would perform the same as Observer Aborts. (But it would not need to poll).

Is this approach valid or is there an easier approach?

Thanks for any feedback / ideas

Does observer aborts necessarily always poll? I’ve not looked into the code, but I’d kind of assumed that one of the reasons for using blackboards was that it can track changes and therefore in theory should be able to avoid that kind of inefficiency.

Like I say, I don’t actually know how it works, just guessing.

Thanks Kamrann

Not sure about the built-in Blackboard Decorator, going to check on that… but a new BlueprintBase decorator does “poll” by firing the PerformConditionCheck event every bt tick.

In fact, just checked source and found following comment:
// if set up as observer, and has a condition check, we want to check the condition every frame
// highly inefficient, but hopefully people will use it only for prototyping.

Good to know - guess I might research making an event-based blueprint alternative

Thought I would elaborate further…

Kamrann - you were absolutely right - the blackboard decorator is not ticked, but triggered by blackboard observer events. It is an observer for any changes in the blackboard.

So for my hypothetical situation, “Alien lands, everyone runs”, one approach would be that the alien landing event updates all relevant blackboards, and these will cause the correct decorator events.

Thanks again for sending me down the right path…

Yep, in that case you should just be able to set a boolean blackboard value to true when your event fires and have observer aborts set on a blackboard decorator. Might be a little more complex dealing with when the boolean should reset, but I guess that would be the easiest approach.

Good to know that they are indeed more efficient in this scenario.