ExternalBehaviorTrees question

Similar to this thread:

I have a handful of gameobjects the player controls very similar to a RTS/squad type game. It appears ExternalBehavior trees are the recommended way to go if you plan on issuing orders from runtime, correct? I plan on having an orders/job system similar to the above post where there will be small BT's (external) to do various operations. The key requirement is that i load all these during runtime (via eventing handled through buttons/hotkey in the UI to issue orders to the units).

I have 2 questions:

1) Are ExternalBehavior trees the way to go if you want to load/run/enable/disable through runtime? It seems this is the approach the system would like us to use.

2) I have some prototyping code that I have been playing around with and so far its been working good. However, in the below code it runs "Orders_Test" twice. Orders_Test BT only has one Task - Log which has a message 'xyz' and it is playing twice. I have triple checked that this is the only BT in the scene and i have it nested in a right click event and the right click event is only logging once so it seems like somewhere within the BT logic. Thanks!

Code:
string behaviorTreePath = "BTs/Orders_Test"; // Path to the Behavior Tree asset in the Resources folder

ExternalBehaviorTree behaviorTree = Resources.Load<ExternalBehaviorTree>(behaviorTreePath);

BehaviorTree behaviorTreeComponent;

behaviorTreeComponent = gameObject.AddComponent<BehaviorTree>();

behaviorTreeComponent.ExternalBehavior = behaviorTree;
 
1) Are ExternalBehavior trees the way to go if you want to load/run/enable/disable through runtime? It seems this is the approach the system would like us to use.
As noted we're having a similar party in the other thread...

My answer to your question would be yes, that or using BehaviourTreeRefernce tasks within a BT. Totally depends on where you want to handle things in code, or how far you want to go writing custom tasks.

Regarding the duplicate logging, I'd ignore that for now and proceed with getting a more realistic setup going, like having BehaviourTree components on your agents and loading trees at runtime. Just by doing a more realistic implementation, even as a test, you may resolve multiple issues.
 
Ok, thanks so much for the reply, appreciate it. I'll keep going with External Trees then. If you have more insights and updates to your project, i would love to see them/hear about them as i think we are implementing a similar scenario.

Also, on the logging issue, yes, i agree, ill try something a little more complex -- however, i was just curious if, in my code, it was correct and I was configuring the external tree correctly. I thought maybe i needed to configure the external tree first then add teh component or something along those lines. It's bizarre why my external tree is executing twice. Is that the general 4 lines of code that you use to load and execute an external tree?

Thanks again for the input!
 
I generally have all of my external behaviour trees linked in the editor to my AI manager so I avoid everything to do with Resources.Load, something like this:
1684338819470.png
I also usually have the BehaviourComponent already on my agents because they are prefabs, but makes no difference if you add it at runtime or not as far as I know.
I assign the external behaviour tree at runtime the same way you do, there's a code example of my AI init method in this thread:

Part of your code doesn't make sense, you are declaring a behaviour tree object then adding a behaviour tree component to it. You would normally have an AI agent gameobject (like some character or enemy or whatever) and have a single BehaviourTree component on that, then assign the external tree to that component at runtime. Or for a simple test set all of that up in the editor. Once it works in the editor, move to assigning your external tree in code at runtime.
 
Top