Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: blackant on February 03, 2015, 06:50:26 AM

Title: When Does a Loop Count Start ?
Post by: blackant on February 03, 2015, 06:50:26 AM
yeah, everything is in the title,

i have sometimes a loop count stop because it reach 1000,
but sometimes i have nothing...

and the script is always following the sames steps, so why sometime i have nothing and after it say this overide ?
Title: Re: When Does a Loop Count Start ?
Post by: wheretheidivides on February 03, 2015, 11:24:10 AM
Could you show the code (I am assuming you are using playmaker) and it'll be easy to figure out.  Pics are always nice.
Title: Re: When Does a Loop Count Start ?
Post by: blackant on February 04, 2015, 04:01:30 AM
don't know if it will serve you the code is so big...
Title: Re: When Does a Loop Count Start ?
Post by: 600 on February 04, 2015, 04:12:00 AM
I use "Next Frame Event" action in these situations, put it in a new state and connect somewhere in the middle where you see a loop of states.

"1000 loop" is like a safety switch so Unity won't crash.
I believe this is something to do with the pc calculation speed at that moment, so if Fsm with multiple states have not much variables to update it can loop more than 1000 times in one frame.
Title: Re: When Does a Loop Count Start ?
Post by: Lane on February 04, 2015, 07:34:45 AM
It means you don't have a properly controlled loop. Sometimes using Next Frame Event works, other times the problem is more fundamental and just a poorly designed loop without proper logic gates. If you turned off the 1000 loop catch then your framerates would plummet due to this bad loop needlessly running so many times.

For instance, you have State 1 where you do Float Add and FINISHED transition to State 2 which does something else and also uses FINISHED to go back to State 1..

In this case, the loop is going to immediately transition as soon as the action stack in State 1 is finished, which will take pretty much no time at all, then go to State 2 and when its done, continue the loop. Sounds like... A loop, right? Yeah, but it's totally ballistic! Playmaker will catch the 1000+ error because in a single frame it ran this loop that many times since there is no gate that says wait for this event, wait for a period of time, or whatever. Its a bad loop. In the event that you had to do this loop a specific number of times then this would be fine, for instance creating random jewels on a screen or something and iterating through them until finished.

To fix it, you could 1) Put it all in State 1 and run it every frame. That would make it only run once per frame, instead of doing it as fast as possible in the same frame. 2) Use a Next Frame Event to tell it to wait one frame before sending a transition. 3) Tie the loop to some other logic that it depends on so that it executes the loop on an as-needed basis.
Title: Re: When Does a Loop Count Start ?
Post by: wetcircuit on February 04, 2015, 11:45:00 AM
Ahh thank you! I was actually thinking that run every frame would do the opposite (make it happen MORE often, not less)....
Title: Re: When Does a Loop Count Start ?
Post by: Lane on February 04, 2015, 12:01:24 PM
Well, Every Frame will make the action perform its purpose once per frame. Thats technically more than not running every frame, but in this case where a loop is involved and it actually designed to do things as fast as possible in a single frame with no exception or gate logic then yeah, its going to break it.

Additionally, with an action using Every Frame it will never transition out of the state via the FINISHED action because the action never finishes if it is running Every Frame. You could force a transition, or force FINISHED to fire off, but it will not naturally use the FINISHED system event if there is an action using Every Frame in the stack.