I’m using NodeCanvas FSM’s for agents in my game, and I’m trying to create save functionality.
Is it possible to save the state of an FSM exactly during runtime? I would like to be able to save the FSM and the “FSM state” of each agent in my game, so that I can load a save file, and each of the agents will be in exactly the same state as when they were saved?
This would mean that the currently occupied node of each FSM would be saved, as well as how long the agent has been at that node.
Just wondering if this was possible, and if so, could someone point me to a useful place in the documentation?
This is unfortunately not possible out of the box, but you could create a simplified save system for your agents where you can save the current state name of the agent (FSMOwner.currentRootStateName) and later (after loading the previously saved name), trigger that state directly via FSMOwner.TriggerState(string stateName).
As for saving the duration the agent has been on a state that would be far more complex and would require a lot of custom code. Are you certain you have to save the duration the fsm state has been running?
For your information, please note that you can save and load blackboard variables which can also prove to be useful in certain cases. You can save and load a blackboard variables via the Blackboard.Save and Blackboard.Load methods (which is a simplified version which saves to PlayerPrefs by a provided string ‘key’, or for a more manual approach, by utilizing the Blackboard.Serialize and Blackboard.Deserialize methods, which will return the serialized json string (from Serialize method), which will then have to be provided for loading (in Deserialize method).
Thank you for your input, that’s really useful and has given me some good ideas moving forwards. As long as I hadn’t missed something very obvious in the documentation!
Thanks for your quick response, I’ll have a think about implementation again and perhaps get back to you, cheers.
Author
Posts
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.