Hi there, I have some questions related to FSM performance and optimization hopefully someone can give me some guidance on!
My project involves a prefab NPC (just a single 2D sprite) which has a FSM containing around 100 states (all pretty simple actions that control a schedule the characters moves through- eg navigate to bar, wait, navigate to roof, wait, etc). As the game progresses the amount of these NPCs increases into the hundreds, sometimes over 1000 simultaneously. Everything is working great (playmaker has been incredible), but it does get to a point where it starts crashing on iPhone- I'm guessing its just running out of memory.
I have been through all the actions and optimized heavily based on tips in other threads:
-No 'find object' or other expensive actions
-No 'every frame' style actions. etc
So... a question specifically about the FSM component itself, as I realize there might be some opportunity for broader optimization. The NPCs go into a waiting state for 5 minutes at each location they visit. This is just a single state with only a 'wait' action inside it. But of course the entire FSM component is still 'active' (containing the 100 states and 20 or so variables).. is the rest of this FSM taking up a 'cost'? Or is the current state it is in the only relevant thing here?
Optimization ideas:
1. I thought maybe instead, when the NPC enters their wait state, they could send an event to a new FSM which only has 2 states in it, a wait state and a 'return to active' state. This wait state could deactivate the original larger FSM component for those 5 minutes, then when complete, it would reactivate the main FSM component and return it to previous state. Thus the majority of NPCs on screen would have inactivate FSMs at any given moment -Would having the FSM component deactivate actually help though?? Or is activating a small FSM when deactivating the original large FSM having a 0 net change.
2. Does deactivating array/hash list proxy components when not being used help at all? Each NPC has a few of these that they use only at certain parts of their schedule.
3. Instead of deactivating the FSM component, would deactivating the whole object be a bigger saver? I could replace my NPCs with a static sprite when they are in their 5min wait state.
Any small optimizations multiply out massively as the NPCs increase. So any guidance here would be amazing!