playMaker

Author Topic: Restart FSM ?  (Read 4753 times)

HuGo

  • Playmaker Newbie
  • *
  • Posts: 4
Restart FSM ?
« on: May 23, 2013, 04:33:30 PM »
Hi

I got a few panels with FSM on them.
I switch from one to another thanks to a fadein/fadeout managed by iTween.
It's an NGUI Panel so I don't need to Disable/Enable them each time, just hiding them.

I wish my FSM restart from the START entry point each time I switch a Panel on.
Currently, only Deactivating & Reactivating the FSM is working thanks to the "Reset on Disable" option.

If I try the invoke action Reset on an FSM it just clear it up.

If I to use various Send Message action nothing happen.
I can't find any official documentation on that "Reset on Disable".
Is there any public method to do this rather than put a Global event or De/Activate my GameObject ?

Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart FSM ?
« Reply #1 on: May 24, 2013, 01:54:24 AM »
Hi,

 sorry, what is the expected behavior you want? I am not sure I follow

bye,

 Jean

HuGo

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart FSM ?
« Reply #2 on: May 24, 2013, 05:17:15 AM »
If it's easier to read code for you,
I need to achieve the same things happening when executing this action
(AKA restarting any given FSM)

Code: [Select]
using UnityEngine;
using HutongGames.PlayMaker;

[ActionCategory(ActionCategory.Logic)]
[Tooltip("Best way I found to RESTART a given FSM...")]
public class RestartFSM : FsmStateAction
{
public PlayMakerFSM FSM;

// Code that runs on entering the state.
public override void OnEnter()
{
FSM.enabled = false;
FSM.enabled = true;
Finish();
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart FSM ?
« Reply #3 on: May 24, 2013, 05:26:51 AM »
Hi,

 ok, This doesn't look too bad actually. Are you concerned about performances?

 I never reset fsm, never had the need too. Maybe because I use a a different technic when I need to "reset" a behaviour. Basically, then, I never rely on the component serialization to restart, but simply store the values myself in a system like a database or something simpler, and simply manually create a Reset system within my Fsm, calling a event "RESET" or something, that will read what ever data is needs to reset.

It is an overhead, but it feels more confortable this way, as I have true control over all aspect of the behavior.

bye,

 Jean


Bye,

 Jean

HuGo

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Restart FSM ?
« Reply #4 on: May 27, 2013, 12:20:36 PM »
Hi Jean
thanks for you anwser.

In fact, it's not a bad idea either.
I was thinking this way cause I always try to minimize to its maximum FSM complexity.

By the way, it is exactly my current "issue" with FSM. I don't know much how far should I go with states and events network.
Because I'm using NGUI, I got a bunch of delegates for every widgets in my games, adding an event call on everyone of them, passing variables and methods over PlayMaker suddenly feel more cumbersome than simply create a piece of code and link function to delegates.

So I'm a bit stuck between a mix of simple OO coding and piece of FSM doing simple things.
I guess I still need to know where to use them wisely (like AI or Game Logic perhaps) rather than thinking I should do everything inside PlayMaker. Or else it will just be a big mess.

Thanks for your answer :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Restart FSM ?
« Reply #5 on: May 28, 2013, 01:56:03 AM »
Hi,

 that's a fact of life  I am afraid :) any project can reach scary proportion and becomes a mess, with or without playmaker :)

 the key here is to define "mess". In our case, you want to have a component that sits between ngui and playmaker, to pass events. that's not messy, it's simply the way Unity works, it's all component based, so you shoudl embrace it, it's meant to work this way.

 Also, you have to weight the benefit of using playmaker here. If it helps you create logics, or avoid scripting, then it's a fair trade if you have to insert some in between components to links various frameworks together.

The mess in your case could arise by not carefully brainstorming what you actually need, especially around that reset system. Maybe prefab could help, maybe some tricks could complelty avoid having to manually reset Fsm, etc etc. So before you dive into this, make sure you experiment first, to gain experience. This is the most difficult part, knowing exactly what you need before doing it...


bye,

 Jean