Is it possible to save the state of a BehaviorTree?
Specifically I want the AI to pick up exactly where it left off when the game is loaded, executing the same node in the tree.
Is it possible to save the state of a BehaviorTree?
Specifically I want the AI to pick up exactly where it left off when the game is loaded, executing the same node in the tree.
Hi , exactly save the state to run from there when the game is loaded again i am dont sure if can be do it. but probably you need this for debug your BT, and just in case, if you dont know it, when you run the BT you can Pause, Stop, Backward Step, Forward Step etc ON REALTIME and this is a AWESOME !! feature for debug your BT. Maybe this can help you.
Also another GREAT tool for debug is the Visual Logger:
Best regards,
What I do is in my SaveGame class, I have a struct to hold all the necessary data for my AI, such as variables that my blackboard contains, an enum for the state my AI is in (such as idle, patrolling, searching, combat), etc. When I save my game, it makes a new instance of that struct and adds it to an array for each enemy in the level. It doesn’t store the EXACT state of the behavior tree, but the way mine is set up, it works fine for me. If I knew of a way to store which node was being executed and then execute that on loading, I would do that as well.
This is similar to what I’m doing at the minute, I was just hoping there was a better way.
I know how to store the node that’s currently being executed with GetActiveNode(), there just doesn’t seem to be a way to get the new tree to start from that node. The Pause() and Resume() methods are both protected, and the Start() node just goes back to the root of the tree.
It looks like the only thing that’s been marked as a UPROPERTY() in the BehaviorTreeComponent class has also been marked as ‘transient’, so I guess it isn’t serializable by design.