playMaker

Author Topic: Prevent global event override?  (Read 1603 times)

Juneav

  • Playmaker Newbie
  • *
  • Posts: 2
Prevent global event override?
« on: April 02, 2022, 12:47:34 PM »
Hello! Hope you are ok.
Got a question here regarding usage of multiple global events in the same FSM, here's my case:

In a game object I have a FSM with let's say 3 global events, but it could be any number. Each global event follows a unique path of states and actions, all paths ends in a idle state. This FSM is used as a manager for components in it's game object and it's children.

In another game object I have a script, in this script I have a function where I invoke the Manager's global events via code, one line after another, expecting the manager to receive each event, execute it's full set of states and finally land on the idle state.

However, it seems that when I call the first event and it starts doing its job, and then I call the second event it immediately "cancels" the first event path of execution, wherever it were, and starts executing the second event's path .

I know a FSM can only have one active state at a time and the events are being called one after another in a c# function, and I think this is the reason they are being "overriding", but, is there a way to prevent this? Like waiting for the paths to end and land in the idle state? Or should I approach this in a different way?

I'm using this to set some post processing effects, btw

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Prevent global event override?
« Reply #1 on: April 02, 2022, 01:43:30 PM »
Hi.
indeed if you send multiple events in the same frame you will get issues.

you could have a bool checker like Fsm Bool Test (Ecosystem)
and on the fsm where you are sending the global events set a bool to true/false on the first / last of your states.

or instead of sending events, you could set 3 bool values and set to true on the fsm where you normally send the global events (bool 1 event 1 / bool 2 event / bool 3 event 3)

have a state where you do a bool test for each one (3)

on the last state from each path set it to false and loop back to bool test.

Juneav

  • Playmaker Newbie
  • *
  • Posts: 2
Re: Prevent global event override?
« Reply #2 on: April 02, 2022, 10:29:38 PM »
Hi.
indeed if you send multiple events in the same frame you will get issues.

you could have a bool checker like Fsm Bool Test (Ecosystem)
and on the fsm where you are sending the global events set a bool to true/false on the first / last of your states.

or instead of sending events, you could set 3 bool values and set to true on the fsm where you normally send the global events (bool 1 event 1 / bool 2 event / bool 3 event 3)

have a state where you do a bool test for each one (3)

on the last state from each path set it to false and loop back to bool test.

Hi djaydino!
Indeed you are correct, I used the debugger to test and I can see that sending multiple events in the same frame causes overriding.

Im going to apply a divide n' conquer approach by creating children on the manager gameobject, each children will have a FSM with a particular execution path, so this way in my script, I can call any event in the same frame (im actually broadcasting global events, so I can prefab gameobjects with FSMs with no dependencies :D) and since each path will be on independent gameobjects, they will execute correctly and independently from each other :D

Question tho, can I have FSMs with same name right? I didnt see a problem doing this but just to make sure...

Thank you! 

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Prevent global event override?
« Reply #3 on: April 04, 2022, 10:06:51 AM »
Hi.
If the fsm is not on the same game object it is fine (and many cases recommended)

For example i have many objects where i have a 'Data' Fsm, i use that a lot to get for example Data from a picked up object, for Data on enemies etc...