Hello!
I bought Playmaker a few weeks ago and have really been enjoying it!
I had a quick question regarding performance of the InvokeMethod action. To prevent FSM's to be globally accessible, I am handling communication between them via scripts. So if an FSM on object A wants to trigger an event to an FSM on object B, Object A's FSM is invoking a method on itself, and that method is then calling the event on Object B.
My question: Is using Invoke Method frequently a good practice? Best practice is to cache those method calls into delegates. I wasn't sure if PlaymakerFSM caches those upon initialization or if it is using that reflection every time the action occurs.
If Invoke Method doesn't cache the method name into an action, is there any way to do so or is there a better way to accomplish my goal here? I know I could just make the events global, but then I would end up with too many global events and every FSM would have access to every other FSM.
Also, when it comes to using Global Events, I've been told it's best practice to use the fewest amount of static or global objects in a game in favor of Dependency Injection. If we create a Global Event every time one FSM wants to talk to another, it seems like we would have hundreds or even thousands of Global Events, which may get messy as the game builds.
Here's my current task I'm trying to accomplish:
I am adding a Pause Menu to my game. The 4 objects involved are: Input Manager, Game Manager, Pause Menu, and Battle Manager.
Currently, the Input Manager calls events (in script) whenever an Input is received.
The Game Manager subscribed to the event "MenuButtonDown". When that event triggers, my Game Manager sends an event to its PlaymakerFSM by string name. The FSM then invokes the method on the GameManager "ActivateCombatPauseMenu". This method does 2 things:
- Calls the "Activate()" method on the Pause Menu
Calls the "Suspend Combat()" method on the Battle Manager
The Pause Menu's Activate() method then sends an event by string to its own FSM called "DISPLAY". Then it fires off events in code based on what selections the player makes in the menu (such as resuming, quitting, etc).
If I used Playmaker FSM's for everything and use global events instead of calling methods, I would have the following global events:
MenuButtonPressed (sent from InputManager)
ActivatePauseMenu (sent from Game Manager)
PauseMenuResumeGame (sent from Pause Menu)
PauseMenuRestartBattle (sent from Pause Menu)
PauseMenuQuitGame (sent from Pause Menu)
DeactivePauseMenu (sent from GameManager)
SuspendCombat (sent from GameManager)
ResumeCombat (sent from GameManager)
That just seems like a lot of global events just from a pause menu. I'd be worried my event list would get pretty overwhelming over time as the game builds.
Below are the screenshots of my two FSMs. Thank you SO much for your help
Thanks!
Nick
Thanks so much!