playMaker

Author Topic: FSM works in debug, but not in normal play  (Read 1738 times)

prattfall

  • Playmaker Newbie
  • *
  • Posts: 19
FSM works in debug, but not in normal play
« on: May 28, 2014, 09:24:46 AM »
The FSM I have checks for the closest tagged object, checks if it is in sight and then moves towards it and eats it. If there are no tagged objects, it goes to an idle state.

The sight checking and eating are performed by other FSMs.

When I debug this, it works fine. If there is more than one tagged object, it eats them all in order exactly as it should. When there are none left, it returns to the idle state.

However, when played without breaks, it moves to and eats the first one, but for some reason goes through the find closest check (when there aren't any) and gets stuck on the move state, because there's nothing to move towards. Here are two screencasts of the debug working correctly and the normal play not.
https://www.flickr.com/photos/120865053@N02/14103972679/
https://www.flickr.com/photos/120865053@N02/14104114787/

Also (attached) an image of the find closest check state, which is where I'm guessing the problem lies.

To clarify this particular state, I need more than one tag attached to an object and have been doing this with a child object which is empty except for a collider and the extra tag. So once it's found an object, it gets its parent object, then acts on it or sends it to idle if it returns null.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4000
  • Official Playmaker Support
    • LinkedIn
Re: FSM works in debug, but not in normal play
« Reply #1 on: May 28, 2014, 07:59:23 PM »
Is priorityObject set by another FSM?

The order in which FSMs on different GameObjects are updated is not guaranteed. Maybe that is causing problems here...? When you debug you've paused one FSM and allowed all the others to run before continuing - manually guaranteeing the execution order!

If the order of execution matters you should have the "instigator" FSM send an event to the dependent FSM. The dependent FSM can then safely update knowing the other FSM has been updated first.

prattfall

  • Playmaker Newbie
  • *
  • Posts: 19
Re: FSM works in debug, but not in normal play
« Reply #2 on: May 29, 2014, 06:19:20 AM »
Oh, I understand, that makes a lot of sense. I don't think that game object is being set by another FSM, but the insight about order not being guaranteed is a concrete way in for me. It just made no sense to me before. Thank you very much!

prattfall

  • Playmaker Newbie
  • *
  • Posts: 19
Re: FSM works in debug, but not in normal play
« Reply #3 on: May 29, 2014, 09:05:03 AM »
No, of course, priorityObject *is* being set by another FSM - on a game object handling triggers...

My question is, if the FSM shown in the image above is at some state - say "Move to Priority Symbol" - and then receives the event "Home Trigger" what does the FSM do? Does it remain on the current state and ignore the event, remain on the current state and queue the event, change state to "Find Closest..." or somehow run both states concurrently? From the log window, it looks as though it registers the trigger but otherwise ignores it, but I expect it's more complicated than that and that might be where my problem is.