Hi there
I’ve recently read some of Mat Buckland’s AI book on setting up an FSM including the miner example. I did start to implement this in Unity without too much trouble, but I did have a sense that it was all a bit ‘cumbersome’.
I then started reading some info Jodon Karlik’s website at http://www.codingjargames.com/blog/ which was more unity specific. He suggests a simple way of implementing FSM where each of the states are just child objects, and you enable and disable the children to change states. The OnEnable and OnDisable functions of scripts on the object can then be overriden as the transitions into and out of the states, and the Update function can be used when the state is running. The parent to the child objects could include the ChangeState() function.
This all seems like a great idea to me - I am just trying to learn and do some simple stuff and need a robust way to start creating states and handle transitions. However I then noticed that If I wanted to say call WaitForSeconds from within OnDisable() as a state was exiting (to allow time to do something before the state change), I can’t, as OnDisable cannot be a co-routine. If I try and call WaitForSeconds in a separate function from within OnDisable, I get an error as it won’t execute:
“Coroutine couldn’t be started because the the game object is inactive”
Any suggestions?