What architecture should be used for AI Behavior trees?

Hello. Im trying to make different types of AI enemies using Behavior trees. And Im trying to figure out what the architecture for my game should look like. Right now I have an enemy BP base class and any enemy I make will be a child of this class. Each AI child class uses a different behavior tree, and currently, Im exploring the idea of having the same BT_tasks be used in different behavior trees. These tasks would only call a function in the enemy base class which would call another function/event that’s in the child class there it will do its own unique code.

So for example the AI determines it needs to do an attack so it executes the task called “AttackPlayer”, all that this task does is it casts to the base enemy class and calls the Attack function that’s in it. From there the child classes can override the base class function with its own code. This way I can make each attack, movement, dying (and so on) Task be reusable in the different behavior trees and it would reduce the number of tasks in the project.

The downside to this is that I cant aces some useful nodes in the child class but I can access them in the Task blueprint, like, “Delay” or “AI move to” which has the useful “On Success” exit.

I want to hear someone else’s opinion on this. Is this a good idea or would it just be better to have a different “AttackPlayer” Tasks, with the main logic in the Task, for each of the behavior trees?

Hey @Luurio!

What you’re doing is exactly how you should do it! Reuse of already existing code is ideal. :slight_smile: Whatever you can do to have the same behavior tree and tasks for as many pawns as possible is best in most cases.