Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: Rebooter on October 03, 2019, 03:36:07 AM
-
Is there a way to send an event by name to a specific FSM (also by name) from a C# script? I found PlayMakerFSM.BroadcastEvent() from a tutorial video, but it sends to all FSMs. I want to use a string array of FSMs.
-
Hi.
maybe the PlayMaker API (https://hutonggames.fogbugz.com/default.asp?W329) can help
-
Hi,
Can you check out the PlayMaker utils from the Ecosystem, I created a series of c# apis to facilitate this.
and I just made one to fit your request:
PlayMakerUtils.SendEventToGameObjectFsmByName(null, <gameobject>, <fsm name>, <fsm event>,null);
Let me know how it goes :)
also, do you need this on a global scope and not target a specific GameObject? if yes, I can also make it, but it will be dangerous as only the first fsm found with that name will be called, but I guess I could make it that all fsm with that name gets called. let me know.
Bye,
Jean
-
I had to try several different approaches to solve the particular problem I was having and I finally got to storing the FSMs I needed to call the event on in a list, and I loop through the list and use 'fsmList.SendEvent("Init");'
I also use elsewhere:
var fsm = PlayMakerFSM.FindFsmOnGameObject(_fsmGO, fsmName.Value);
fsmInitManager.RegisterFsmInitState(fsm);
The reason I'm doing it like this is to make it easier to manage as it was taking 3-4 actions per FSM to do what I needed, so I wrote a few scripts to simplify it. This is to make sure certain FSMs have completed intializing some variables, etc., before the main FSM tries to use them.
I had noticed that when using breakpoints, sometimes I would get weird behavior. I think what was happening was that the breakpoint was doing something that affected the timing, in other words the stuff I had in the 'Start' states wasn't reliably being completed before the main FSM would send an event that I believe was causing the Start states not to complete.
But I see now that I shouldn't have assumed the 'Start' states would work in the way I was using them, so now I just have a blank state under the 'Start' event on certain FSMs, and I have an 'Init' event that the main FSM calls on each sub-FSM. Each sub-FSM is stored in a dictionary with a bool indicating if it has completed initializing. When all are true, the main FSM can continue to the next state.
Thank you for making the new action, that can be useful.
I don't currently need the 'global' option as I just needed to target specific FSMs (some on other gameobjects). Originally I was going to use strings for the FSMs and the Events, but now I'm getting references to the FSMs directly from within the action.
-
Hi.
For something like you explained i usually have a separate fsm that has a 'Bool All True' action (every frame checked) and several bool variables. then from the other fsm's when they are ready i use a 'Set Fsm Bool' to set one of the variables on the fsm with the 'Bool All True' action.