Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[Upcoming] Easy State FSM Editor

Discussion in 'Assets and Asset Store' started by thepigeonfighter, Sep 26, 2019.

  1. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    While making a game with animals in it, I quickly started needing something like a FSM to organize my animal behaviors.I didn't want an entire visual scripting solution but I wanted something that worked similar to the way the Unity Animation Window worked.
    Something simple that wouldn't take very long to learn at all. I found many FSM implementations but none fit the bill for me personally. So I ended up designing my own. My main goal was to keep it simple and try to make the process of editing it as quick and intuitive as possible which resulted in Easy State.
    AssetStore
    Here is the trailer for it :



    I have made a short tutorial on how to implement the worlds simplest state machine using easy state. So you can get an idea on what the workflow looks like.



    Here is another longer tutorial on how to implement a more complicated FSM

     
  2. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Just made another youtube vid to displaying the workflow from start to finish.
     
  3. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Really excited about this update coming out. It is a complete rewrite of this asset. Would love to hear some thoughts.
    Cheers

     
    tapticc and Innocent-Dev like this.
  4. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Just finished a sort of "Hello World" type of tutorial to show an idea of how this tool works.
     
  5. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    Hello, can you offer some advice on how to set up events on prefabs? I've been trying to use this on a prefab character that is used multiple times for a team based game. Also the documentation and videos don't really go into how to configure prefab instances, specifically their initial data values unique to a given prefab instance so would be great if the documentation could be expanded in that area. The asset is easy to use generally, the documentation that is available is of high standard though. It will force me to make sure code is in the right places and not mixing concepts so I really want to make use of it, but prefab implementations are proving tricky for me :)
     
  6. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Hey there thanks for checking this asset out. Funny you should ask this, literally yesterday discovered a bug related to prefabs.
    It appears as if certain things aren't triggering the component dirtied event. I'll have to look into it more to see how to fix it. In the short term a work around is to toggle some other property like "RefreshType" this triggers the event that something has changed and then appears to save the changes. As a note you can't actually drag the event handler scripts straight into the 'EventHandler' field(s). You must first attach the event handler script to a gameobject (typically the same object as the state machine is on) now that it is a component you can drag that component into the field reference.

    Does that make sense?
     
  7. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    I managed to attach the event now, thanks for the tip on how to get around losing the reference :)

    I had to create a reference to the gameobject in the fsm data type and manually set this when the fsm instance is initialised, but I think I should just use the FSMTarget.gameObject, this is an area I would like to see guidance on if you are updating the manual at any point. Basically in the Act method, you don't get access to the FSMTarget so need to store the reference to gameObject
     
  8. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Yes you are precisely right. There is no way to access the gameObject via that Act method. I was trying to keep the Act method as lightweight as possible, but it might be worth investigating the performance cost/vs convenience of passing a reference to the gameObject. I am currently working on a large update for Easy State. I don't want to give any word on timelines at this stage but I will add that to my list of things to investigate. Thanks.
     
  9. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    I'd be happy to help with any testing if you are after user input
     
  10. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    The other thing I will be working on is the multiplayer networking aspect. I only want the host to determine certain state data so will be exploring how best to split out what the client can do without approval and what needs to be server-auth only, and how FSMs fit into that all
     
  11. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Ok great, that's good to know. It'll probably be a little while before I have something worth testing but I'll reach out to you when I do have something worth testing to see if you're still interested/have the time. If you want me to look more into providing a reference to the target gameObject in the Act method I am sure it'd be pretty simple and i could send you the scripts to update if you wanted to make it work that way for your particular project.
     
  12. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    That would be helpful, sure :)
     
  13. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Give this a shot. I think this will do what you are looking for.
     

    Attached Files:

    tapticc likes this.
  14. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    Will give it a bash tomorrow thanks!
     
  15. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    Hello, I had to make a small change to ConditionalAction.cs to make it compile:

    public override void Act(T data, GameObject gameObject)
    (added the GameObject, pass that to the decoratedAction.Act as well)

    This needed a Using for UnityEngine of course, but it works well and saves me having to create my own references.

    Are there any "best practice" approaches to setting initial state data for individual instances of a gameobject by the way - should you have an initial state that is called SetupState or similar, use that to initialise initial state data and then once done transition to some other state?
     
    Last edited: May 15, 2021
  16. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Oops I must have forgotten that. Thanks!
    I believe all initialization should be done using event handlers as once inside a behavior the update loop is similar to the typical Unity update loop it is just that you have more control over how many steps it takes to complete an update cycle. So that being the case it seems to me that you should do all set up before a Behavior starts. As with everything I'm sure there are exceptions but this would be a general rule of thumb. Now as far as do you actually set up objects in the event handlers themselves? That is up to you. To me it seems like that'd work for most cases but if you have many objects that need special and unique initialization, I might set up some sort of manager with a Register/Unregister method that takes in your data type instance as a method parameter. At which point I'd register the the gameObject (with the state machine on it) to this manager. The manager would initialize the values and then if necessary unregister(and possibly serialize the new data) from the manager once no longer needed.
     
    tapticc likes this.
  17. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    I had a problem yesterday after refactoring the name of a class after already building a behaviour. The name of the old class was persisting so I tried cleaning the database using the provided menu option, it didn't work and in the end I had to remove EasyState and start again. Obviously this won't be practical once I get a few behaviours set up, would you mind checking renaming classes (event handler and data type) after they have been used in behaviours as refactoring is something that just happens while tidying up code and there's a risk of losing work
     
  18. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Ah yeah, I imagine that would cause some issues. I'll have to look into this. I don't think I can send a quick fix for this issue. It'll probably have to be added in the update I am working on. For now I would treat this as a limitation and avoid renaming classes. I'll look into this though and if I come up with a simple solution I'll let you know. Thanks for the heads up!
     
  19. tapticc

    tapticc

    Joined:
    Jan 16, 2014
    Posts:
    379
    No worries, refactoring to make code more obvious is something I try keep on top of so will be a hard habit to lose!
     
    thepigeonfighter likes this.
  20. brittany

    brittany

    Joined:
    Feb 26, 2013
    Posts:
    93
    I am learning how to use Easy State and wanted to study the Sample scenes but when I try to run any of them I get the error "Could not load selected behavior. Make sure it did not get deleted." and none of the scenes do anything. It is on a completely new project I made just to test it. All I have done is import Easy State. Do you have any ideas what is going on there?
     
  21. thepigeonfighter

    thepigeonfighter

    Joined:
    Nov 7, 2017
    Posts:
    37
    Hey there,
    For each of the demo scenes there is a README asset describing what is required to get them to work. Are they not working after following those instructions?
     
  22. brittany

    brittany

    Joined:
    Feb 26, 2013
    Posts:
    93
    Thank you thepigeonfighter! They are working now. I just didn't notice those instructions. Sorry!

    For anyone else who is having this problem, there is some setup you have to do for each demo you want to try. First you have to open the Context Wizard, and in the upper left corner there is a settings icon, open that then where it says "Database Folder Path", you have to paste in the link to the "Easy State Database" folder for that particular demo. Then save your changes and the demo will work.
     
    thepigeonfighter likes this.