playMaker

Author Topic: Events and Global Events  (Read 8762 times)

Marc Saubion

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Events and Global Events
« on: March 05, 2018, 04:15:04 AM »
Hi everyone.

I've been using global events to send orders from an object to the other. My understanding is that we should use regular events for inside orders, and globals when orders get out of the FSM.

I just tried sending and non global event to a gameobject using "send event by name" and it worked. So my question is, is it a bug or a normal feature?

I'm working on a new workflow system and intend to exploit this so I don't bloat my global events list with non general events, so I'd like to make sure this is not going away.

Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Events and Global Events
« Reply #1 on: March 05, 2018, 07:22:44 PM »
Hi,
No its not a bug and its here to stay :)

I also use 'send event by name' a lot, especially for my sample tutorials as it is a big hassle to import/export globlals for newbies.

Even my global variables have a maximum of 1 or 2 atm (and 0 for the tutorial samples)

The only thing at the moment is that you can't see the target local events (yet!)
So you need to be careful not to use the wrong event name :)

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Events and Global Events
« Reply #2 on: March 06, 2018, 12:25:25 AM »
One more advice, you can be tempted to be lazy and simply broadcast to all, try avoiding that, send events only to fsms intended to receive them to minimize the possibility of error, and be careful when naming the events, of course.
« Last Edit: March 06, 2018, 03:11:54 AM by krmko »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Events and Global Events
« Reply #3 on: March 06, 2018, 03:33:25 AM »
Hi.
@krmko :
Did you have cased that you had errors with this?

I commonly use broadcast all to 'Start' the main game (after a countdown for example)
and on an endless runner for a removal countdown.
But never had errors yet.

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Events and Global Events
« Reply #4 on: March 06, 2018, 09:41:42 AM »
Hi.
@krmko :
Did you have cased that you had errors with this?

No.

Marc Saubion

  • Beta Group
  • Junior Playmaker
  • *
  • Posts: 79
Re: Events and Global Events
« Reply #5 on: March 08, 2018, 08:42:41 PM »
Thanks guys, that's good to know.

@krmko, I never used "broadcast to all" for that very reason, plus it seems very inefficient performance-wise.

@djaydino, I also do have that case of checking when a game start. I chose a global bool an a state containing bool test and bool changed. This way it works even if the game object is spawned after the game started.

...

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
Re: Events and Global Events
« Reply #6 on: March 09, 2018, 02:22:24 AM »
Actually, when i THOUGHT i had the same error, it was always the case of rogue fsm, the one i've set to send an event and forget about it.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Events and Global Events
« Reply #7 on: March 10, 2018, 05:29:42 AM »
Hi,
So far i had never seen performance issues or that some fms don't work.

But i only use broad cast all if i need to cast to many fsms at the same time.

the only variable that i use as global now is gameobjects, like for my 'Game Manager' , 'Player Manager' and other "Managers"

On a case like you use a bool when spawning a prefab, i will place a bool on the game manager and use "Get Fsm Bool" and then Check the bool.

Bool changed is using every frame so i tend not to use that if there is a other possibility not using every frame (with any other variable also btw)

Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 312
    • Andrii Vintsevych
Re: Events and Global Events
« Reply #8 on: December 24, 2020, 07:36:56 AM »
Global event has another advantage over send even by name. If you use send event by name, it's harder to debug, cause Playmaker can only show you fsms that receive event in Even browser. But when you use global events it will show you fsm that sends event and receives event, cause it creates event in fsm that sends it.

I usually use Send Event By Name, but when I've discovered that advantage, I've started to wonder if this is the right approach. Cause with "send even by name" approach, the only way to find fsm that send events is "by hand" and memory.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7620
    • jinxtergames
Re: Events and Global Events
« Reply #9 on: December 25, 2020, 07:35:57 AM »
Hi.
I have not notice any performance issues with it yet, and i am using send event a lot more that before as well.

a good thing to know is that you can group event names by using a /

for example
Enemy/Attack
Enemy/Patrol
this way these will be grouped as Enemy

You can even do subgroups like Enemy/Behavior/Attack

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 808
Re: Events and Global Events
« Reply #10 on: December 26, 2020, 06:24:46 AM »
Broadcast to all could be more expensive but I didn't notice any fault with it and if you're clean in the way you name and use your events, there won't be any issue. One option that allows to spray an event on a limited range is to send to children when targeting a parent that's at the top of some hierarchy in the scene.

On a design side of things, sending a non global event by name to other FSMs is a violation of the principle of local vs global events. I'd rely on these methods rather sparely. It also lacks readability. If these are conditions that do not worry you, then you might be just as good using the Go to state action which forcefully reroutes the flow of an FSM into a given state.

I never send events by name, it's not log friendly.

On a case like you use a bool when spawning a prefab, i will place a bool on the game manager and use "Get Fsm Bool" and then Check the bool.

There's FSM bool test that directly grabs the bool.


Gua

  • Beta Group
  • Sr. Member
  • *
  • Posts: 312
    • Andrii Vintsevych
Re: Events and Global Events
« Reply #11 on: December 27, 2020, 11:48:06 AM »
One option that allows to spray an event on a limited range is to send to children when targeting a parent that's at the top of some hierarchy in the scene.
Just couple days ago I've discovered "send event to children" was causing a performance hiccup. I've sent it to a parent of quite complex object with lots of children and FSMs, but from now I'll try not use "send event to children" when I can.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 808
Re: Events and Global Events
« Reply #12 on: December 27, 2020, 04:58:19 PM »
It's always better to make the extra effort of targeting specific FSMs but that's part of the optimization. On small tree hierarchies it's totally affordable.
If a G.O. has many FSMs on it, you'll also have to target FSMs directly too.
Also if you want to keep the upper states that send events as small as possible, you can always use relays through FSMs on targeted children that will target their own smaller children, and so on and so forth.

You can also use an alternative by remotely setting FSMs' bools for example. The targeted FSMs will have a state that keeps an eye on bool changes (checks if becomes true or false, or simply if there's a flip of value), in a way similar to what Marc Saubion explained.

Christoph

  • Beta Group
  • Sr. Member
  • *
  • Posts: 255
Re: Events and Global Events
« Reply #13 on: May 29, 2023, 04:32:35 PM »
Bumping this old thread since I just am trying to understand more the difference between global events and normal events used for global transitions.

Thing is, my project has tons of global events. And most of the time, these are used only once or twice in the entire project. Would it make sense to use local events instead with the "Send Event by Name" action?

If you have lots of global events, is it bad for your project in the same way we shouldn't be using global variables? I mean does it make your project less performant or laggy?

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 808
Re: Events and Global Events
« Reply #14 on: June 01, 2023, 01:25:45 PM »
Playmaker is relatively self aware of what events are being used and by what state or FSM. But when using fields which are manually typed in (it means it's a string's field), this awareness stops. This applies to variables and events.

So, if you need to know where your events come from (Events tab, "sent by"), don't use this action.