Multiple behavior trees or a single one for Idle and Patrol?

Pietrofonix

New member
Hi guys, I'm working on a behavior tree for the enemies and I have a question. The detection branches are the same for everyone, but there are essentially two types of overseeing behaviors (there can be more), Idle and Patrol. If I want to distinguish this behavior inside the tree, do you recommend to do it in a single tree with maybe a custom node that checks for a bool and switch branches between Idle and Patrol, or make two trees one with Idle and one with Patrol and keeping the detection branches inside both? Is there a better way to do it?

Here is the picture of my generic behavior tree. Inside the red box is where I would put the branches for Idle and Patrol.

NPC - Stealth Tree edit.png
 
Last edited:

Justin

Administrator
Staff member
if I want to distinguish this behavior inside the tree, do you recommend to do it in a single tree with maybe a custom node that checks for a bool and switch branches between Idle and Patrol
Yes, that's the approach that I would take. Since Idle and Patrol cannot run at the same time it'll be easier to manage within the single behavior tree.
 

Pietrofonix

New member
Yes, that's the approach that I would take. Since Idle and Patrol cannot run at the same time it'll be easier to manage within the single behavior tree.
Ok, but what if certain enemies only stay in Idle during oversee, and others only in Patrol? Should I create a node inside the single tree that checks the type of the NPC, where the Behavior Tree component is attached, and switch branch based on that?
 

Justin

Administrator
Staff member
Yes, that's appropriate. Behavior tree designs are like programming in that there's no one way to do things. If having multiple trees makes more sense to you then I recommend going with that. In your specific case you can also use external trees and load the tree at runtime depending on the type of agent it is. To do this you'd override the GetExternalBehaviors method within a BehaviorTreeReference subclass.
 

Pietrofonix

New member
Yes, that's appropriate. Behavior tree designs are like programming in that there's no one way to do things. If having multiple trees makes more sense to you then I recommend going with that. In your specific case you can also use external trees and load the tree at runtime depending on the type of agent it is. To do this you'd override the GetExternalBehaviors method within a BehaviorTreeReference subclass.
Ok perfect, thank you very much šŸ˜ƒ. Sorry for all these questions, I'm new to Behaviour Trees and I'm trying to learn as much as I can
 
Top