playMaker

Author Topic: FsmBuilder: How do I create a new Fsm ?  (Read 3844 times)

xsmarty

  • Playmaker Newbie
  • *
  • Posts: 14
FsmBuilder: How do I create a new Fsm ?
« on: May 02, 2013, 12:23:06 PM »
Hello,
I am building an alternative View for Playmaker.
For this purpose I need to create a Fsm manually. However, after several trials, i failed since the Fsm constructor doesn't init all the necessary data.

In order to find an alternative, I use the FsmBuilder.AddFsmToSelected();
But that magic method gives me a hard time. If I use it, Fsm get initialized, however should i not use it and add the component myself, it does not work anymore.
So first question would be what extra calls "FsmBuilder.AddFsmToSelected" does that an Addcomponent doesn't ?
And also, how do I Create a Fsm manually ?

Code used:
public class myFSM: PlayMakerFSM
{}

In some code{
        GameObject go = Selection.activeGameObject;
// comment next 3 lines and B does not get properly init.
        FsmBuilder.AddFsmToSelected();
        PlayMakerFSM A = FsmEditorUtility.FindFsmComponentOnGameObject(go);
        if (A.Fsm == null) Debug.Log("done by AddFsmToSelected");

        myFSM C = go.AddComponent<myFSM>();
        if (C.Fsm == null) Debug.Log("empty fsm when done by AddComponent myFSM");
       
        FsmEditor.SelectFsm(C.Fsm);
}

Many thanks.

Additionaly,
It looks like the PlayMakerFSM() doesn't initialise the PlayMakerFSM.Fsm.
Is this Intended ?
Is the PlayMakerFSM.Fsm readOnly also intended ? Could it be made writable ?

code used to guess this:
public class A : PlayMakerFSM
{
    public A()
    {
        if (this.Fsm == null) Debug.Log("fsm not yet init");
    }
}

« Last Edit: May 08, 2013, 08:21:56 AM by xsmarty »

xsmarty

  • Playmaker Newbie
  • *
  • Posts: 14
Re: FsmBuilder and associated magic
« Reply #1 on: May 08, 2013, 08:06:34 AM »
Bump.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: FsmBuilder: How do I create a new Fsm ?
« Reply #2 on: May 08, 2013, 10:04:33 PM »
PlayMakerFSM is a MonoBehaviour so it doesn't use a constructor. It gets initialized in Awake().

Use GameObject.AddComponent to add a PlayMakerFSM to a GameObject and it should get initialized properly.

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.AddComponent.html

xsmarty

  • Playmaker Newbie
  • *
  • Posts: 14
Re: FsmBuilder: How do I create a new Fsm ?
« Reply #3 on: May 10, 2013, 12:48:18 PM »
I Nailed it finaly !  8)

Prior to ANY use of FsmBuilder, one needs to use FsmEditor.SelectFsm( YourFSM );
There is an internal static pointer to currently selected Fsm.. just took me 1 week to find what call sets that.

For future users :
Should you want to create your own Fsm, derived directly from a PlayMakerFsm object, you need to (in this order):

1/ AddComponent<YourFSM >()
2/ FsmEditor.SelectFsm( YourFSM );
3/ Use all FsmBuilder static and methods for your purpose.

Do not :
Create objects manualy to then append them to YourFSM.Fsm, it won't work.

Future Api improvements :
1/ Put Fsm as a read/write instead if just a read function ?
2/ Make the FsmBuild function self contained, with all responsabilities on its side.
I might say it is a bit akward to go through the view, to set the model rigfht now.


« Last Edit: May 10, 2013, 01:03:19 PM by xsmarty »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: FsmBuilder: How do I create a new Fsm ?
« Reply #4 on: May 10, 2013, 01:03:12 PM »
Sorry, I didn't realize your goal was to use FsmBuilder. I though that was a workaround to add the Fsm...

Yeah, right now FsmBuilder is pretty tied to FsmEditor. I'd like them to be more separate, but they were developed together and FsmBuilder had no other clients, so dependencies crept in... :(

So are you building an alternate EditorWindow to FsmEditorWindow? I have to warn you that the FsmBuilder and FsmEditor classes are not documented, so you might have to hack around to find stuff...

xsmarty

  • Playmaker Newbie
  • *
  • Posts: 14
Re: FsmBuilder: How do I create a new Fsm ?
« Reply #5 on: May 10, 2013, 01:09:02 PM »
Sorry, edited post during your reply :).

I am doing a sequencer (Timeline clips, just like in Adobe première) but with underneath playmaker FSM ( 1 per track).
That's the whole idea.
I am not happy with other plugins found, and since i need to have two views of the same data (because i need to then serialize it (save/load) ), i went for a crazy extension of Playmaker :)

Too bad that you didn't comment your api :)
If you have other warning, feel free to gimme heads'up :)
cheerz.


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: FsmBuilder: How do I create a new Fsm ?
« Reply #6 on: May 10, 2013, 03:09:01 PM »
Sounds like a cool project :)

My only other warning is that we can't guarantee future compatibility with the editor API. To be honest, I didn't really see people using the editor API. The runtime API is a different story... we aim not to break common usage in that API (sending events, accessing variables etc.).

Having said that, the editor API hasn't changed a lot. If anything I'll try to clean it up some for public consumption. :)