playMaker

Author Topic: A lot of Send Events with Event Data  (Read 3572 times)

DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
A lot of Send Events with Event Data
« on: July 18, 2019, 11:35:31 PM »
I'm using 'Set Event Data' and 'Get Event Info' to communicate between gameobjects.

But I seem to have a problem making it work consistently. The 'get event info' gets 'sent by'-variable set to another object in the scene, but the object in question doesn't send any events to this object - making the FSM getting the wrong values and not from the actual object Setting the even data and sending the event/making the state change.

Is this a bug or how it should behave? As in: 'get event info' just takes from the latest even sent by any object, even if it's not making the state change?

Should I just go back to setting and getting the variables directly from the gameobjects FSM's?

I'm using playmaker 1.9.1 b13 and Unity 2019.2.0b9
« Last Edit: July 19, 2019, 11:03:58 AM by DanielThomas »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: A lot of Send Events with Event Data
« Reply #1 on: July 19, 2019, 03:42:58 AM »
Hi,

 yes, be careful, even data is unique and not per Event, it's a global data, so everytime you set event data, get event info will get this latest data even in an fsm that came into an active state from a different event, it's not related.

to overcome this, I either use SetEventProperties ( is you have PlayMaker Utils) which lets you define key/value and so you can create keys that are unique for a given event and not mix up data. Or I use a next frame event in the cascading logic omf my flow to give fsm a chance to act upon the reception of a given event, and use next frame event before sending the next step of logic.

Bye

 Jean

miguelfanclub

  • Full Member
  • ***
  • Posts: 165
Re: A lot of Send Events with Event Data
« Reply #2 on: July 19, 2019, 06:51:25 AM »
"Get event sent by" is also inconsistent.

For me, this is one of my biggest issues with Playmaker. I always "hardcode" the one who is sending ("Hey its me who is calling you") so the receptor can do a callback to him back to continue once he is finished.



DanielThomas

  • Beta Group
  • Full Member
  • *
  • Posts: 150
Re: A lot of Send Events with Event Data
« Reply #3 on: July 19, 2019, 11:03:44 AM »
Still get this problem with the 'Set Event Properties' acting inconsistent.

I'm guessing it just boils down to I don't know how these event data and event properties actually work in the scene.

I made a new scene, added two objects, one that sets event property every 1 second and one that gets the event property. Then I set a break point on the get state. When I run the scene the get event never get's the value because of the breakpoint. While this wasn't my point it somehow made me feel it's not as straight forward as I though and there are caveats.
What if two FSM's send data with the same key to two other FSM's, is it possible , in theory, that they overwrite eachother?

I would love to use these as it keeps the FSM's easier to read, but seems I will need to stick to 'Set FSM variable' before sending the event for predictable results, for now.

Prestonh

  • Playmaker Newbie
  • *
  • Posts: 44
Re: A lot of Send Events with Event Data
« Reply #4 on: July 22, 2019, 03:03:29 AM »
I think they would overright each other if they are on the same frame.  I guess depending how its set up.  One thing ive learned, is to watch for event names.  I make sure the global event name is completely unique to all other events global or local.   Its caught me a couple times (apparently i dont learn from screwing up the first time)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: A lot of Send Events with Event Data
« Reply #5 on: July 23, 2019, 02:38:23 AM »
Hi,

 Two fsm sending two identical event data type with different value is not a good idea, you won't be able to enforce order and one value will get lost.

when you know have this case, you need to either create a buffer array, where you add values to an fsmArray and then have the fsm process each value one at a time. or you put some next frame event to prevent the situation to begin with.
 
the other possibility is to not send data and host it locally, then when you send an event, the receiver can use GetFsmXXX targeting the sender of the event and get the data stored on that sender fsm.

Bye,

 Jean

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: A lot of Send Events with Event Data
« Reply #6 on: March 16, 2021, 02:09:31 PM »
Well, I suspected something like that going on behind the scenes but I think it deserves to be better reflected in the actions' notes; my project has transited across several versions and I did come into critical problems where data would be set, events sent, but the receiving GOs would not get the data.

From a manager FSM, I was associating an object type var, then sending the event to a targeted GO (so it's very specific) and then in the same action I was repeating the same process for four more different GO targets.

I had discovered "set properties" way too late into the project, even if it happened a while ago, but as far as I could implement it I can attest to the fact that it's faaaar more reliable than setting data with the other actions.
Besides, it allows using FsmArrays directly. It allowed me to circumvent the issue of missing attached data but now this annoying limitation or bug has returned once again to haunt me and this time it is affecting a whole chunk of code that is just way too huge to refactor.

This happened as I moved to 1.9.1. I really enjoy PM but updates are stuff of nightmares. It simply never goes on nicely.
This is why I made a post about a necessary feature to really understand how events are working under the hood, how they are exchanged between FSMs and what kind of data they carry at a specific given time.

@DanielThomas
Breakpoints can mess up with events and their respective monitoring.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: A lot of Send Events with Event Data
« Reply #7 on: March 16, 2021, 03:51:20 PM »
yes, be careful, even data is unique and not per Event, it's a global data, so everytime you set event data, get event info will get this latest data even in an fsm that came into an active state from a different event, it's not related.

This is quite at odds with what users might understand from the descriptions, especially on the actions which are specific to var types.

"Sets Event Data before sending an event."
"Sets the Int data to send with the next event."

It gives off the idea that the data package is unique to each event that is about to be sent next.
There's an implied "local" buffer since as long as no event is sent, the data package might be overwritten (changed) by any new set up until an event is actually fired from the current FSM, but from your description of the data being global, assumptions I ran with for quite some time now are now proven false.

So just how global is the data package exactly?

Say I have two FSMs, Fsm1 and Fsm2, either both sending the same event to different targets, or both sending two different events to different targets; if the data set up is done in Fsm1 but then doesn't fire any event, and Fsm2 sort of short-circuits this and sends its own event after the data set up but before Fsm1 sent its own event; is Fsm2's event going to use the data package as set up in Fsm1?

Or is the data pack set in a given FSM exclusive to this FSM, even if two (or more) separate FSMs all send the same event after, and only after, the setting up is done?

Besides the {{}} don't seem to have any effect on the formating inside the information section.

Quote
to overcome this, I either use SetEventProperties ( is you have PlayMaker Utils) which lets you define key/value and so you can create keys that are unique for a given event and not mix up data. Or I use a next frame event in the cascading logic omf my flow to give fsm a chance to act upon the reception of a given event, and use next frame event before sending the next step of logic.

But the globality of the data package remains the same, right?
Set Event Data uses default properties and Set Event Properties allows the user to define custom properties if I get this right.

As I explained above but it might not be clear enough, I encountered a problem a certain number of times during the development of my app where data would simply not be sent. I'm not saying data was overwritten, it was simply absent.
Typically this happened inside a state where I did:

1. Define GO target
2. Set up data
3. Send event to target

And this block was repeated a few times inside the same state, mainly because spreading this over several states created unnecessary clutter and the whole series of actions within the state was still small enough as not to generate a monster, and especially not warranting any complicated dynamic self-looping construct.

The event itself was always the same, like for example HELLO instead of HELLO_T1 (for target 1), HELLO_T2, etc.

In the "bug", not a single GO received any data, not even the last GO which you might think would at least receive data as defined in the last setting up. It's just blank everywhere as if there was a data-writing/encapsulation conflict during the same frame.

Two fsm sending two identical event data type with different value is not a good idea, you won't be able to enforce order and one value will get lost.

Hmm... "two identical event data type with different value"
You mean setting up data twice using FsmInt for example in both cases, once with 0, the next time with 4618?

Would there be a problem if I did this:

1. Set Int data = 0
2. Send BYEBYE to target 1.
3. Set Int data = 4618
4. Send BYEBYE to target 2.

Is there a risk of target 1 actually receiving the data that was meant for target 2?
Or target 2 not receiving any data until BYEBYE is received by target 1 and the data extracted?

All that time I thought events were treated as instances of one event template, and each one was unique, but are you saying that they are in fact sequential, as there exists only one single version of a given event at a given time, and that until BYEBYE for target 1 isn't received, target 2 won't receive BYEBYE?

Quote
when you know have this case, you need to either create a buffer array, where you add values to an fsmArray and then have the fsm process each value one at a time.

I'm not sure how that would differ much from my case, aside from this new step:

0. Set up FsmArray (once)

 1. Define GO target
 2. Get data at index n from FsmArray
 3. Set up data
 4. Send event to target

Repeat (with n incremented each time)...

Quote
or you put some next frame event to prevent the situation to begin with.

This might not be feasible because of the loss of performance in some cases where data has to be transmitted within one or two frames at most.
« Last Edit: March 16, 2021, 03:55:04 PM by Broken Stylus »

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: A lot of Send Events with Event Data
« Reply #8 on: March 17, 2021, 10:21:22 AM »

This Set Event Data action is even weirder than I previously thought and it turns out I've been lucky for a long long time.
For starters, Get Event Info can collect a FSM name but there's no way to set up that with Set Event Data.
So you would think, if it cannot be set ahead of sending the event, does it mean this peculiar case implies the action can find the sending FSM name on its own? No, that's just not the case at all.
I know this because I modified one my receiving GOs so it would receive a number of different vars for the purpose of the test, and it turns out it's been able to find a FSM name despite absolutely nothing being set up on the sending end. I can't even understand how this FsmName string could even return anything, above all with the value I found as it points to a second FSM on a parent prefab, but this FSM is simply never referenced by any event.
This is seriously weird.

I even changed some of the code so all the targeted FOs I talked about in my former post are now receiving their own unique event, but that does not change a thing, they don't get the data at all!

For the first time since I decided to use more of the Set Event Properties action ages ago, I decided to look into the action's entrails and saw that it uses more than just a different type of Data, it's exactly using properties, something quite different, and this for some reason seems to be totally spared the aforementioned weirdness.

Therefore, until a proper and detailed explanation is provided as to how this event data stuff really works, I'll say stick to Event Properties, it's much more safe to use.

I also confirm that you must use a unique key otherwise if you use, for example, myInt as an attached property to different events (yes, different), since the property package is also global, shared across all events and singular (one for everyone), the last value used to set myInt (or any other given key) will be used for all Get Event Properties action that look for this key.

This is true if you do everything with the same frame. If spread over several frames with one event received per frame, you might have enough time to get the data stored in the same key used by everyone before it's being set again for a second, third, etc. event.
I think events are managed late in the loop or even received on the next frame, which might explain this.

The consequence of this being that you will need to make the property name (the key) dynamic if many GOs must receive different values of the same type at once through the Properties package.
In other words, unless you manually set different names for the same key type, you'll have to do something like building different key names (string) for each different targeted GO, by having something like "damage" being the static part of a property of the interget type and "_target1" being the appended dynamic suffix wherein 1 can be 2, 3 or even 423, resulting in the key name being "damage_target1" for example, then "damage_target2", etc.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: A lot of Send Events with Event Data
« Reply #9 on: May 10, 2021, 07:06:26 AM »
Hi,

 event data works the same as eventProperties,

at the time of sending the event, the event data or properties is stored in a global place, and while the send data is not overriden somehow, this event data will remain available.

so, if you change the data several times very quickly ( multiple times per update for example), this will be problematic because some fsm that listen to them events might not have the time to process the event with the right data.

Bye,

 Jean

justifun

  • 1.2 Beta
  • Sr. Member
  • *
  • Posts: 280
Re: A lot of Send Events with Event Data
« Reply #10 on: October 24, 2021, 10:04:49 PM »
@jeanfabre - So what's the best way to do it then if there's possibilities of data getting lost?

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: A lot of Send Events with Event Data
« Reply #11 on: October 25, 2021, 06:04:03 PM »
Hi.
I always use Set Fsm actions (Int/Bool/String/etc.)
then a Send Event (By Name)

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 772
Re: A lot of Send Events with Event Data
« Reply #12 on: October 27, 2021, 02:05:02 PM »
yes, be careful, even data is unique and not per Event, it's a global data, so everytime you set event data, get event info will get this latest data even in an fsm that came into an active state from a different event, it's not related.

This is actually some critical information that should be visible in the documentation. I switched to properties a long time ago but without knowing about this one-token type nature, it can puzzle new users just like I was puzzled, especially since there's just no information about events themselves to be read in the Editor.
'Current Event Data' in the supplement is hardly helpful if we don't even know what event is carrying the data, which event Playmaker is actually computing at any time, etc.