Efficiently Running Dynamic Behavior on an NPC

Hello,

I need some guidance on the best approach to efficiently run dynamic behaviors on an NPC.

Requirement:

As part of my game’s design, the NPC follows a predefined path, moving from one waypoint to another. At each waypoint, the NPC should execute a distinct behavior.

My Approach:

My current plan is to implement a Master Behavior Tree that includes a Run Behavior Dynamic child task along with other default waypoint tasks. At each waypoint, I create a behavior tree specific to that location and attach it to the Master Behavior Tree at runtime using the SetDynamicSubtree method.

Question:

Since my NPC frequently moves between waypoints, this approach requires frequent updates to the child behavior tree. Will this frequent subtree swapping introduce performance issues? Has anyone dealt with a similar requirement, and if so, what optimizations or alternative approaches helped maintain performance?

Behavior trees will work but can become cumbersome when you start doing more complex behaviors, but a more future proof technique may be State Trees and Smart Objects as BTs are generally falling out of favor. They are pretty much custom built for the type of behavior you are describing, and are what are used for setting up custom interactions between actors:

The smart objects allow you to embed it’s own state tree to activate on the actor when an actor interacts with it. This behavior may require another plugin, GameplayBehaviorSmartObjects maybe? There are several plugins that work with smartobjects… if you are more comfortable with behavior trees there is a similar plugin that integrates behavior trees and smart objects also.

It’s a big chunk of meat to bite into, but really powerful once you get set up.

2 Likes