How can I get behavior trees to stop clearing their blackboard values when switching to a new blackboard?

I’ve got several different behavior trees, each of which has its own blackboard, and NPCs will switch between these different behavior trees at different times in the game. I’m using the blackboard values in part to track where in the behavior tree each NPC is.

However, when switching to a behavior tree that uses a different blackboard, it clears all the values from the previous blackboard. So if I return to the first behavior tree, it can’t remember where in the tree it was. This doesn’t happen if you switch to another behavior tree that uses the same blackboard, so I guess I could make every behavior tree use the same blackboard, but then what’s the point of having distinct blackboards?

Is there a way to keep the blackboard values when switching behavior trees? Or if not, is there a better way of tracking where in the behavior tree an NPC was when it was here last? Thanks!

Hi @cakebread , sounds like you have a pretty good handle on the scope of the problem, so I’ll break down some of Your questions. I also dont have the source code in front of me, so im working off of memory. Hopefully you will find something useful in my response.

IIRC you would have to override the BrainComponent to save multiple blackboard states, even then, I wouldn’t be surprised if you run into garbage collection issues.

What we typically do in this situation is identify all of the commonalities between blackboards and either, A.) Create a monolithic BB like you suggested, or B.) Cache a struct of the critical information on the AIController for re-instantiation of your long term data. If you have multiple BBs then you might want a TMap of them, which comes with another set of management headaches like adding a new key to your map every time you add a new blackboard.

Having separate blackboard, in my opinion, is more to capture different states. My agent has a perceived world state, which may be different from the team’s world state, which is definitely different from the commanders world state.