Hi! I’m currently working on implementing “stateful” FSMs (that is, storing the execution state of NC FSMs into our savegames) and I have a pretty much working approach for now:
(1) Restoring blackboard variables
(2) Looking up the previously active node instance in the FSM node collection
(3) Instructing the graph owner to start the FSM behaviour
(4) Manually call “EnterState” the state from (2) on the FSM instance
(5) Voilà , FSM will run from the stored state on
I just have a slight “one-off” error when starting the FSM behaviour – it will always execute the actions in the primary node in the FSM before switching to the target node. What would be the best way to start the FSM immediately at a specific node so there are no unwanted side-effects from the actual prime node?
Glad to hear you were able to customize the FSM to your requirements 🙂
Probably the best way to handle this, would be to actually set the “Start” state before starting the FSM behaviour.
This can easily be done so by setting the ‘FSM.primeNode’ property to the ‘FSMState’ you want to become the Starting state. After that is done, you can safely instruct the GraphOwner to start the FSM behaviour and you can also disregard step 4 as well since the FSM will start from the desired state you want to already 🙂
That actually works pretty well for the main state machine – but I can’t get it to work with nested FSM nodes. The nested FSM node needs to be entered before I can access the runtime instance of the FSM – when I change the prime node on the referenced Prefab before the node runs, the prime node will change for all other instances, too. And additionally – wouldn’t changing the prime node of a nested state machine persist when the nested node is entered again? So the nested FSM would have changed its behaviour overall because it will start on the wrong node on subsequent runs.
I guess the easiest way will be too keep my original behaviour and just enforce the prime nodes to be neutral for all FSMs, so the small enter glitch won’t have any effect, or do I miss something?
Yes, what you state here is very true. I wasn’t aware you were also using SubFSMs, so my suggested solution is totally out of the question 🙂
I suppose the next best thing to do, would be -like you said-, to have an empty/neutral Start state in all such FSMs.
I hope this is an acceptable solution for what you are after. If not, I could take a deeper look to see how to support this in one way or another.
Thanks!
Join us on Discord: https://discord.gg/97q2Rjh
Author
Posts
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic.
Login
Register
By registering on this website you agree to our Privacy Policy.