Conditional Aborts and Events

tikitofu

New member
Hi, I've seen similar questions about this on the forum, but still can't figure it out:

I'd like to be able to constantly run an "Idle" state while waiting for events. After an event is received and the task is completed, I would like it to return back to a waiting idle state, ready for another event.

Would using a Selector would be the best choice here? Also, I think lower priority would not work here since they all have equal priority.

Thank you!

1608590669967.png
 
Last edited:
I am able to get it to return to idle after performing a task by adding a Repeater before the Selector. I can also get it to switch tasks via Has Received Event by using a Lower Priority conditional. However, I cannot go from Task A to Task B because of the hierarchy. Getting closer...

1608592096461.png
 
Branches on the left have a higher priority than branches on the right so I'm glad that you found the conditional aborts sytem.There have been a number of questions on events so I recently updated the documentation for a structure that works well: https://opsive.com/support/documentation/behavior-designer/events/

Has Received Event will clear the received event as soon as it is activated so the number of times that it is received doesn't matter. You'll need to create a new task similar to Has Received Event if you want to add in the functionality of it mattering if the event is received multiple times.

In terms of switching between Branch A to Branch B, Branch B will run whenever the first Has Received Event task returns failure but the second returns success.
 
Hi Justin, thanks for taking a look (& the link). I think I understand about the branch conditionals, but in my case it seems to not allow lower priority branches to cancel higher priority (it works fine the other way around). In other words, I'd like the ability to switch tasks without letting them finish if an event is sent.

If that's the case, how do I set up a tree where I can freely switch between branches using HasRecievedEvent at any time?
 
For more control over when a tree is aborted you can use the Interrupt/Perform Interruption task. There is an example of this in the RTS sample project and will give you complete control over when a branch is aborted.
 
Hi, I was unable to find an interrupt example in the RTS project. Do you remember what unit/behavior? TY
 
I just checked and it looks like you're right. I think what happened is that it actually was in the CTS sample project, and that project used to use hte interrupt task but now it uses conditional aborts.

There is an interrupt task though in the Mini Gauntlet sample project
 
Would it also be possible to have each of these branches as separate External Behaviors - and load them as needed?
 
There isn't a built in way but with some scripting you can call FindTask and then assign the PerformInterruption.interruptTasks variable to the interrupt task.
 
Ok, I'm still trying to understand the workflow - I've noticed you can add multiple Behaviors to a single GameObject. Is the intention to be able to switch between them? If so, how are those accessed/used?
 
Behavior Designer doesn't limit you in your design so if you want to have multiple behavior trees on the same GameObject. You can use the Start/Stop/Restart Behavior Tree tasks to start them. The CTF sample project has multiple behavior trees on the same GameObject.
 
You can use the Start/Stop/Restart Behavior Tree tasks to start them
How is BehaviorTree.Start() and Stop() used if you have multiple behaviors within the same tree? I can't seem to pass a name argument, etc..

To be clear, I'm adding multiple trees this way, not multiple BehaviorTree components.
1612991177843.png
Or should I just add more than one BehaviorTree component?

Thanks!
 
In the gauntlet example it seems to be running tasks that eventually complete. But what if you wanted to have the following tree:
toggle between and Idle and a Wander (2 tasks that run infinitely) by using external events (like from a button)? I'm still failing to switch with interrupts in this scenario.
 
If you have multiple trees on a single GameObject you can use the Group index to change a specific tree.
 
Top