playMaker

Author Topic: Send Event from multiple FSMs at scene start [SOLVED]  (Read 153 times)

Malaussene

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Send Event from multiple FSMs at scene start [SOLVED]
« on: May 07, 2019, 02:41:39 AM »
Hello All!

New to Playmaker, I'm doing some tutorials to get the hang of it.
I'm doing one on arrays right now.

I have a GameManager with an FSM and a global array, and some cubes which add themeselves to it.

For what I understand, it is best to avoid using global variables so, instead of using a global array, I'm trying another way and using a Send Event Action with a
global event from the Cubes to the GameManager.

The GameManager listens to this and, when triggered, it gets the gameobject sender and adds it to its array.

Problem is: there are multiple cubes in the scene and all send the same event at the same time and when the scene starts I find only one cube added to the array.
But I don't think the issue is related to this (same timing of event), since if I put a 0,0001 delay to the Send Event action of ALL the cubes, the array successfully populates with all the cubes in the scene. I think there is some sort of issue with sending an event as soon as the scene starts.

Is this known? I couldn't find anything with a search. Is this going to be an issue at all, since a minimal delay on the Send Event seem to "bypass" the problem?

Thanks a lot!
« Last Edit: May 07, 2019, 06:31:28 AM by Malaussene »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3630
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: Send Event from multiple FSMs at scene start
« Reply #1 on: May 07, 2019, 04:28:29 AM »
Would need to look at your setup to be sure, but this sound system like a MonoBehaviour execution order issue. The execution order of MonoBehaviours is not guaranteed in Unity. So the GameManager could update before all the Cubes have finished updating. So you do need to tell the GameManager to wait, but I would use the Next Frame Event instead of a short delay to give the Cubes one frame to register themselves.

Malaussene

  • Playmaker Newbie
  • *
  • Posts: 2
    • View Profile
Re: Send Event from multiple FSMs at scene start
« Reply #2 on: May 07, 2019, 06:30:42 AM »
but I would use the Next Frame Event instead of a short delay to give the Cubes one frame to register themselves.

Oh.. sounds a lot better.
Gotta make aquaintance with nearly all the actions Playmaker offers yet. Next Frame is one of them.
This works fantastic. Thanks!