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
Login
Register
By registering on this website you agree to our Privacy Policy.