playMaker

Author Topic: Restart Level Action loading level twice?  (Read 11348 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart Level Action loading level twice?
« Reply #15 on: September 20, 2013, 07:02:57 AM »
Hi,

 ok, maybe I should look at the project itself then, cause there is likely something missed out.

bye,

 Jean

mschweitzer

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart Level Action loading level twice?
« Reply #16 on: December 05, 2013, 11:35:25 AM »
Is this issue going to be addressed sometime soon? This issue was one of the last remaining bugs our team encountered that was holding up a patch release.

Not 100% sure why it happens sometimes, but it looks like PlayMaker gets confused about which state it's in after a SendEvent call and re-enters the state in the PlayMakerFSM component's Update function.

This is a *huge* problem when using iTween actions because of iTween's conflict checking feature, where iTween will destroy a previous iTween component that is similar to a newer iTween component. It means that if this bug occurs with an iTween action, the FSM will get stuck on the iTween action forever. I had to work around the problem by modifying iTween to call its "oncomplete" callbacks when it hits a conflict. This at least allowed iTween actions to finish.

Here's a stack trace of the first entry to the state:
iTween:Launch(GameObject, Hashtable)
iTween:MoveTo(GameObject, Hashtable)
HutongGames.PlayMaker.Actions.iTweenMoveTo:DoiTween()
HutongGames.PlayMaker.Actions.iTweenMoveTo:OnEnter()
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:UpdateStateChanges()
HutongGames.PlayMaker.Fsm:DoTransition(FsmTransition, Boolean)
HutongGames.PlayMaker.Fsm:ProcessEvent(FsmEvent, FsmEventData)
HutongGames.PlayMaker.Fsm:Event(FsmEventTarget, FsmEvent)
HutongGames.PlayMaker.Fsm:Event(FsmEvent)
HutongGames.PlayMaker.Fsm:Event(String)
PlayMakerFSM:SendEvent(String)
OurCustomComponent:ChangeFsmStateNow()
<WaitThenChangeFsmState>c__IteratorC6:MoveNext()

Here's a stack trace of the second entry to that same state:
iTween:Launch(GameObject, Hashtable)
iTween:MoveTo(GameObject, Hashtable)
HutongGames.PlayMaker.Actions.iTweenMoveTo:DoiTween()
HutongGames.PlayMaker.Actions.iTweenMoveTo:OnEnter()
HutongGames.PlayMaker.FsmState:OnEnter()
HutongGames.PlayMaker.Fsm:EnterState(FsmState)
HutongGames.PlayMaker.Fsm:SwitchState(FsmState)
HutongGames.PlayMaker.Fsm:UpdateStateChanges()
HutongGames.PlayMaker.Fsm:UpdateState(FsmState)
HutongGames.PlayMaker.Fsm:Update()
PlayMakerFSM:Update()

I believe the second entry to the state happens the next frame. Not sure if this has anything to do with it, but note that the SendEvent call (the first entry to the state) happens from a coroutine. We had to do this because of another PlayMaker bug where you can't use the FSM until 1 frame after you instantiate a prefab containing the FSM.

mschweitzer

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart Level Action loading level twice?
« Reply #17 on: December 05, 2013, 02:25:36 PM »
I tried disassembling the PlayMaker.dll to follow my stack traces. Maybe the switchToState variable in the Fsm class is set correctly in the SendEvent call, then sometime before the next Update() call, it's incorrectly set back to the active state?

As far as I can tell, switchToState is only set to a non-null value in 2 functions: DoTransition() and Start(). I didn't think that DoTransition() was the culprit, so I tried looking at Start(). It looks like Start() immediately calls UpdateStateChanges(), which immediately calls SwitchState(), and my stack trace clearly shows the state switch coming from Update(), so I guess I'm not sure how the switchToState variable is being set to the same state again before the call to UpdateState() in Update().

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart Level Action loading level twice?
« Reply #18 on: December 09, 2013, 02:10:53 PM »
Hi,

 Are you positive you can't solved this by refactoring the way you handle level loading and itween actions?

 I get the feeling you are over thinking this. Maybe you should simply hack this simply using a global variable or some player prefs to maintain a flag that the last level loading was handled or not.

As I am saying this, it strickes me as a deja vu :)

If you can can share with me a repro scene, I would look at it. Did you feel a but report on this already?


bye,

 Jean

mschweitzer

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart Level Action loading level twice?
« Reply #19 on: December 11, 2013, 12:31:52 PM »
I think you're confused about what the problem is here. This isn't a level loading problem. This is a problem where PlayMaker is entering a state twice, which means it is executing actions twice.

In Mayhem's case, it meant that his level load action happened twice.
For me, it meant that my iTween action happened twice.

I think for weird cases like this, giving people source code would at least let us identify the cause of the problem. That could take maybe a couple hours or less. When you have to create a repro scene for bugs like this, there is a lot of guesswork involved because you're not 100% sure what's causing the problem. Also, you could end up failing to create a scene that perfectly mirrors what you have in your original scene, which means that the bug would just never be fixed.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart Level Action loading level twice?
« Reply #20 on: December 11, 2013, 02:36:57 PM »
Hi,

 I didn't assume it's a loadlevel issue herem and I agree: making repro projects requires skills and patience.

 I am having this very issue with the new 2d physics collision, a nightmare! I get repeated TRIGGER ENTER events ( outside playmaker, in an actual regular scripts provided by unity learning team...) and the actually unity sample simply accepts that ( which is beyond me...) and simply listen and filters accordingly. That's why I am having some trouble providing the unity 2d sample as a playmaker solution, I need to overcome this first because within Playmaker, everyone would get very confused, and for very good reasons... but I fail to find a workaround since it's coming from Unity itself to begin with...

Back to your case :)

What could be happening is something outside playmaker, and playmaker simply forward the call twice, because it indeed received it twice... that's likely the case ( can't really say for sure, but 90% sure)

So, you are not alone here :) and the quickest solution is to "accept" it and maintain flags. I am not saying it's a good solution...  :o but it's one that will let you move on.

Can you come back to me next week or aftetr xmas ( I know.. it's far away... but I am swamped...) and keep bumping me so that I have a proper look at this and point at the source of the problem for sure.

Bye,

 Jean


mschweitzer

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart Level Action loading level twice?
« Reply #21 on: December 11, 2013, 04:54:58 PM »
Ah ok, sorry for assuming you thought it was a level loading issue..

The problem we have is that the PlayMaker state machine exposing the bug only does so under very specific conditions in our game. Unfortunately, those conditions aren't obvious at all because there's nothing about the state machine itself or the component sending the event to the state machine that would indicate this could happen.

That's why I started poking around in decompiled PlayMaker code. The only lead I have is that the switchToState variable in the PlayMaker component is getting reset within the current frame or next frame somehow. I'm just wondering how that's possible. I'm suspicious of an initialization bug in PlayMaker because there is some weird initialization code in there, and there have been bugs with PlayMaker initialization code in the past. In the stack traces I pasted earlier, the first stack trace is fine, and expected (switchToState is changing because I call SendEvent on the FSM), but the second stack trace is very mysterious to me. Somehow, from an Update() loop, the switchToState variable is being reset to the active event.

I already worked around the problem by changing iTween itself, so I'm not waiting on this any more. Would just be nice if the issue were fixed. Unfortunately, I don't have a lot of time to work on repro projects since we have deadlines to meet and it would be difficult to justify burning a few work days trying to discover how to reproduce a PlayMaker bug =\

Hopefully enough users out there run into this bug to the point where someone can narrow down whether this is an avoidable user error or a PlayMaker bug.

Thanks jean.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart Level Action loading level twice?
« Reply #22 on: December 12, 2013, 06:11:26 AM »
Hi,

 Are you part of the beta? If you want to, pm me. you may very well be narrowing an issue for sure.

bye,

 Jean