Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: DarkMagicCK on January 13, 2013, 07:54:24 PM

Title: State Entered twice[SOLVED]
Post by: DarkMagicCK on January 13, 2013, 07:54:24 PM
Hi there, I'm troubled with a strange problem.A state will fire twice, and no enable or disable actions exist. So something is done twice, it is not correct.
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_entertwice.jpg)

I dumped a simplified scene which has this problem. Playmaker version is 1.4.5.
The scene is attached in attachment.

I have screenshots at the end of the post.

Logic:
step1. "ctrl_levelController"(let's call it "A") simplely Set "ReadyControllerCount"(call it "count") to 0, and send "ctrl_turnController"(call it "B") event  "setup"(using SendEventByName), wait for "count" to be 1(everyframe).

step2. "B" fires "setup" event, and goes to "setup" state, add 1 to "count", wait for "start" event.

step3. after "count" is 1, "A" enters another state and send "start" event to B, and goes to its final state "NormalLoop".

step4. Problem occurs. B enters the next state twice.

This is a simplified example of my problem. And I really do not know what's wrong.
Please help me solve this, thanks!



levelController:
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_levelController.jpg)
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_levelController_state_StartController.jpg)

turnController:
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_turnController.jpg)
Title: Re: State Entered twice
Post by: Alio on January 14, 2013, 11:04:39 AM
Not an expert by anymeans on playmaker or unity in fact i havent been using either for too long but it seems to me that somewhere in there you are firing off the event twice.  It might be by default or something that when you call for the setup event and it goes into the setup state that once it adds that 1 int it automatically fires into the ThisWillEnterTwice state at the same time its being called for the start event.  Try this.. change that int value to 0. Therefore testing/debugging the event flow line.  According to your actions if your int doe not equal 1 it wont proceed. if you are already firing that start event regardless thus giving you "entering that event twice" it should only enter once this time even though its not supposed enter at all.  if thats the case then you know you need to take out that second event send to "start" event. 

That might be a bit hard to follow my thought process on this one but i hope you kind of get what im trying to say.  I tried to download your sample to test it out but just kept crashing my unity. good luck let me know how it goes.
Title: Re: State Entered twice
Post by: DarkMagicCK on January 14, 2013, 12:08:44 PM
Thanks for your reply!
As your advice, I tried to make the int add 0, so levelController(let's call it A) will not send start event to turnController(call it B). But funny things happened: the "setup" state of B is entered twice.

My playmaker version is 1.4.5, and unity version is 4.0.0f7.

But debug goes easier. I even simplified all extra things, just made two tiny clean FSMs which you can also make in seconds in an empty scene.

step1. Create gameobject 'A' and 'B' add a fsm to both of them.

step2. for 'A': add a start state which does nothing, with a "FINISH" event point to "fireB" state. "fireB" state add a "Send Event By Name" action, and send fire event to B's FSM.
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_firedtwice_A.jpg)

step3. for 'B': add a listener state to B, with a "fire" event point to "fired" state. "fired" state does nothing.
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_firedtwice_B.jpg)

step4. run the game, you'll see B's "fired" state has fired twice.
(http://www.cppblog.com/images/cppblog_com/CK985/14902/o_firedtwice_Result.jpg)

It's really a clean project scene. Can you find any problems?
Title: Re: State Entered twice
Post by: jeanfabre on January 14, 2013, 12:13:47 PM
Hi,

 could you send me the project? I'll see if I can repro this.


bye,

 Jean
Title: Re: State Entered twice
Post by: DarkMagicCK on January 14, 2013, 12:26:03 PM
Here's a unitpackage in attachment, which you need to import playmaker first, and then import this unitpackage.

Playmaker ver: 1.4.5
Unity ver: 4.0.0f7
Title: Re: State Entered twice
Post by: Alio on January 14, 2013, 01:18:34 PM
Hmm im wondering if its just starting and going through all the states regardless.. try doing this.


for B: set Start to empty Idle state.  call it "waiting/listening" whatever.  next where you normally have listener_fire make a global event called fire and set it to that state.  Now for the transition call it something different say "fire complete" and have it then from that transaction go to "fired" state.

If its doing what I think its doing then this should prevent it from going through B without your consent. and have it be Idle until A calls for that event.  You might have to change action "Send event by name" in A to Send FSM Event and select FSM B's global event "fire". Let me know how that goes.
Title: Re: State Entered twice
Post by: jeanfabre on January 14, 2013, 10:52:59 PM
Hi,

Good catch, thanks for the repro pacakge it helped a lot.

 basically, yes there is an issue here. The problem is the start state and the race condition between who gets first called to start.

 It doesn't happen on the current beta. so if you are not part of the beta and want to be, simply contact Alex.

 Meanwhile. I suggest you do the following:

-- it's never a good idea to rely on the start state to fire/listen to events, especially when both gameObject are initialize at the same time ( the yare both on the scene when it starts).

workaround: either you implement some kind of higher level manager that let A know when it can fire events. Or add a simply delay, for example a "Next frame event" on A start state, and then you fire events to other fsm ( they had time by then to have their start state properly ready.

bye,

 Jean
Title: Re: State Entered twice
Post by: DarkMagicCK on January 14, 2013, 11:24:29 PM
OK really thanks, I added a delay to A then everything seems fine.

Looking forward to your next stable release lol.