playMaker

Author Topic: Keep getting Loop Exceed errors [SOLVED]  (Read 2316 times)

mthicke

  • Playmaker Newbie
  • *
  • Posts: 11
Keep getting Loop Exceed errors [SOLVED]
« on: July 10, 2014, 01:35:18 AM »
I've been using Playmaker for quite a while and have gone over most of the tutorials. There's still something I don't get about the structure of a playmaker FSM.

For example. I want to have an object follow my main character at a certain distance. Every time the main character moves, the other will move and then stop at a certain distance away.

I am trying to implement this by getting the distance to the character and comparing it to a float 3.

If the distance is greater it goes to the next state which uses a move towards with a finished distance of 3.

The problem is I get a loop exceeded error. Can I not loop a simple distance test like this?


>>Another way I have tried to do this is:

I have a state that gets the distance and compares it. if the distance is over the limit it advances to the next state. Get Distance and Float Compare are both set to 'Every Frame'. Problem is if I don't loop back from the 2nd state it gets stuck even if the distance is no longer greater. If I return the loop I get the max loop error.

Is it possible to continuously test a condition in Playmaker and perform some action when the condition is met? This seems basic but it keeps tripping me up.
« Last Edit: July 12, 2014, 03:00:10 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: Keep getting Loop Exceed errors
« Reply #1 on: July 10, 2014, 02:21:09 AM »
This happens when you create an infinite loop in your graph. E.g, in a single update, State 1 goes to State 2 which goes back to State 1.

The usual fix is to use the Next Frame Event on State 2 to return to State 1. This says: "I'm done for this frame, but in the next frame return to State 1." Then the loop repeats in the next update...

Otherwise Playmaker keeps looping in a single update and you hit the loop limit. This limit prevents Unity from hanging/crashing which is what usually happens when you code an infinite loop!

Does that help?

mthicke

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Keep getting Loop Exceed errors
« Reply #2 on: July 11, 2014, 01:37:39 AM »
Thanks, it does help. I've used this before but I always thought of it as cheating as if there was some flaw in my logic and this was a bandaid.

I guess I had assumed that each state was only called at each frame. What is the benefit of looping several times in each frame?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3999
  • Official Playmaker Support
    • LinkedIn
Re: Keep getting Loop Exceed errors
« Reply #3 on: July 12, 2014, 12:10:20 AM »
Often you have to break logic into multiple states that need to be executed in a single update. States are fairly generic - they can represent a behaviour that lasts a while, or a single step in an algorithm (like in a flowchart).

Does that make sense?