Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Use Animator as seperate State Machine Node Editor

Discussion in 'Animation' started by OlliQueck, Apr 12, 2016.

  1. OlliQueck

    OlliQueck

    Joined:
    Apr 11, 2013
    Posts:
    49
    I recently started programming AI for my master thesis game. After some time of development i already got thousands of lines of code and a lot of different integer's holding multiple states. All this works fine but is very complex and hard to handle. Especially when i add more states, more animations, more attacks etc. When something goes wrong i never reallly know where the AI got stuck.
    My idea now is to use an extra animator on my characters to control the states like with a node editor. My project will be using UNET so i need to handle AI and animations seperatly. Will this cause problems or performance drops(mobile) when i use a second animator(with no avatar attatched) on my characters to control the AI inside my Javascripts? Some1 has a alternative? Some kind of AI Finite State Machine Node Visualization would be great...

    Cheers
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,713
    When Unity 5.0 exposed state machine behaviours, Pierre Paul Giroux made a blog post Having fun with the new Mecanim features that talked about using Mecanim state machines for non-animation purposes. The examples were a music state machine and a menu state machine, but you could also use it for AI. It provides a nice, consistent interface and parameter-based transitions. It's pretty efficient if you follow the same caveats as animation state machines: don't go crazy with the number of transitions from Any State, and the number of transitions from any particular state in general.
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,340
    There's some drawbacks to using the Animator as a generalized state machine system. In particular, you have to set transition time to 0 in all transitions, and if you forget to, things will break bad. OnStateUpdate can be called after OnStateExit, and before OnStateEnter if there's a transition going on. The sub state machine messages also makes no sense whatsoever, and are useless.

    A better choice is probably to find a dedicated framework for nodes that doesn't have a bunch of animator-specific features attached to it. It's not that using the Animator doesn't work - we're running our AI state machine on it - but you really want a framework where you're in control of exactly when transitions happen, which the Animator doesn't provide.