Behaviour Tree, how to execute a task only once

Hi guys,

I am working on my Boss BT and I want to execute a task when he is gets lower than 50% hp but only once.

Is there any decorator or something else to do this?
Thanks!

The most obvious method is to use a trigger.

If you want to implement via trigger

If you are using timers

1 Like

This can work in normal gameplay BP. But it doesn’t work for a behaviour tree task BP.

So far I think to make a specific task run once is to use a selector compositor and then add decorators to that one-time task. One decorator example would be to check if health is above 50% (which blocks the task if it’s true). Then add a Blackboard boolean key (Done 50% HP task?) that is set once task is performed once and another decorator to check that blackboard key. If it’s true (task has been done before) then it will block the flow to that from playing it after it played once already.

I had a similar issue - I wanted to execute something at “AI Start” just “once” in the behaviour tree.

So what I did was, created a Boolean in the Blackboard called “Start Logic Executed”,

Used a Blackboard Key Decorator which aborts self when this bool is true,

Created a simple service “Set Blackboard Value Bool” where it modifies the Blackboard Key “Start Logic Executed” to True.

Now it just executes it just until my service tells it that it’s been done executing.

Unless you’re actively going to modify those initial values from you behavior tree, you shouldn’t use it to initialize variables.

Behavior trees are meant to “react” to something. So, setting a value one single time defeats that purpose.

INSTEAD: Add your variables to a component, an actor component. And add your default values there. Then just retrieve them form your Actor, and modify your values to it at the behavior tree.