Search Unity

Animation state best practices

Discussion in 'Animation' started by JosephSelahJr, Jun 16, 2021.

  1. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    I'm new to Unity and game development as a whole. Doing a tutorial to get exposure to Unity and I noticed that there is a lot of animation state logic being mixed in with character logic. That just feels like a ticking time bomb. Eventually something will be changed in the animation and that'll break game logic and it'll be a royal headache to track down.

    I'm thinking right now of using a separate state machine for the character and have that state machine drive the animation logic.
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
    That's just one of the many problems with Mecanim. It sounds like you'd be interested in Animancer (link in my signature) which lets you avoid Animator Controllers and control everything directly in scripts. It comes with a state machine system, but it's entirely separate from the animation system so you can just as easily use your own state machine that works however you like it.

    But if you don't want to use Animancer, I do recommend using a script based state machine to control the animations. You still have to deal with most of those problems and waste time maintaining the interdependencies between the code and Animator Controller, but it does at least streamline things a bit. That's what I did back before I made Animancer.
     
    PutridEx likes this.
  3. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    I'll check that out. I'm not planning anything big. But was planning on doing a tiny project with a buddy just for fun. He doesn't code, but he's a good artist. Does Animancer still give him free reign on the art side? I want him able to do what he can with art, I just don't want him able to destroy game state.

    I will say, point 4 is one that's been bothering me. Unity seems to encourage magic strings, which gives you 0 confidence at runtime.

    And 5 is clearly the point I'm bringing up.
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
  5. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    This was very helpful. This was as well-> animancer - Playing

    It looks like a really clean solution.

    I guess if I wanted to be able to have my buddy work out transition timings, I could just create a sandbox script on the gameobject, have two SerializeFields for the animationClips and two SerializeFields for start and stop time and let him muck around. Not much different than the playing example.
     
  6. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
    You certainly can do that, but Transitions are generally better than managing all the separate variables yourself and they give you the ability to preview the animation in Edit Mode.
     
  7. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    I looked into Transitions earlier and somehow missed that Animancer has UI for transitions. That is absolutely beautiful. This library seems like a total beast.
     
  8. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,723
    I just want to reinforce that your inkling here is correct. The animator state machine is horrible and it complicates the workflow way too much for the functionality that it does provide. It has been that way from the start (and it's not going to change, they haven't improved it in a while and they're not going to start now).

    (I have no opinion on Animancer)
     
  9. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    Yeah. It looks horrendous. The input api is ungodly too. I just found the Input system asset. Hoping that's better. I'm honestly horrified with some of the things I see in Unity. I've also seen a lot of magic strings everywhere. It might just be this tutorial instructor. I've already stopped following his code. I'll just read the unity docs if I have questions on the unity api.
     
  10. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
    You might also be interested in Weaver (link in my signature) which can generate procedural scripts for various Project Constants (physics layers, scene names, etc.) so you can use those constants instead of magic strings. I also posted one for Tags here, but it's not yet in the latest version. Unfortunately, Input is one thing I haven't implemented it for because there doesn't seem to actually be anything that gives scripts access to the list of Input Axes (I could make a hacky solution, but didn't want to waste time on it now that the new Input System exists).
     
  11. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    Asset Injection, asset naming and object pooling leap out at me. What comes in the Lite version? Is it just a trial? Since I'm really just getting exposure to Unity right now and if it does morph into a project it'd be just a hobby at least for the foreseeable near future.
     
  12. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,568
    The right column on the Home Page shows which features are included in Weaver Lite. Asset Injection only lets you try it out in the Unity Editor but isn't available in runtime builds without Pro. Object pooling is fully included in Weaver Lite.
     
  13. JosephSelahJr

    JosephSelahJr

    Joined:
    Oct 1, 2020
    Posts:
    18
    Aw perfect! I didn't notice the column on the right before. I'll be checking that out tonight. Thanks a million.