Reply To: How to save and restore the current state of behavior tree?

NodeCanvas Forums General Discussion How to save and restore the current state of behavior tree? Reply To: How to save and restore the current state of behavior tree?

#14988
Gavalakis
Keymaster

Hello there,

The state of a behaviour tree can not be stored entirely as-is. However, the best solution to save/load the state of your characters behaviour tree is to save and load the blackboard variables that the tree is using instead. Then based on these variables and the design of the tree, the flow can be directed towards the branch you need the tree to follow and as such effectively restoring the state of the tree (mostly meaning which leaf node is currently Running).

The variables of the Blackboard component attached on the gameobject (alongside BehaviourTreeOwner) can be saved and loaded through the Serialize and Deserialize methods it has. Blackboard.Serialize will return a json string (which will of course need to be stored somewhere like a text file or Unitys PlayerPrefs), and the Blackboard.Deserialize method takes a string parameter where you basically pass the previously saved json.

Please let me know if that works for you.
Thanks.

Join us on Discord: https://discord.gg/97q2Rjh