Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Animator.Play vs using the state machine

Discussion in 'Animation' started by Alakanu, Jun 11, 2018.

  1. Alakanu

    Alakanu

    Joined:
    Oct 17, 2015
    Posts:
    5
    Hi, I've always wondered: is there a reason why Animator.Play and Animator.CrossFade exist? Are they slower/faster than setting a parameters and triggering transitions? Are those just to be considered a plan b when you have no other choice or are they there for people that can't stand state machines? I don't know you but those function feel like anti-pattern to me.
     
  2. MrDude

    MrDude

    Joined:
    Sep 21, 2006
    Posts:
    2,570
    Hey, thanks, I think you just answered a question I was having! :)

    When I say jump I don't want to wait for the run animation to first play the remaining 50 frames and THEN jump at the end when it eventually checks the transition states... so I simply don't use the whole transition due to a transition condition being met (most of the time) thing. I call Play instead.

    I use transitioning to return to the idle state after doing a once off animation but I trigger my animations using Play (thus skipping the wait for the current animation to finish before it goes to the next one). I forgot there is a CrossFade option. Nice. Now I can trigger my animation faster but still benefit from some transition rather than just cutting from one animation to the other immediately. Cool!

    Thanks for reminding me of that
     
  3. Mecanim-Dev

    Mecanim-Dev

    Unity Technologies

    Joined:
    Nov 26, 2012
    Posts:
    1,611
    @Alakanu
    It depends on each project, some users like to control everything from script, there is also users that don't know how to write code so for them the statemachine transition allow them to define their animation blend more easily.

    there is also some situation sometime that you can't simply define with a statemachine transition because your statemachine is complex, by example a fighting game where one character start an attack but the opponent interrupt the attack and you need to trigger a knockdown animation. So exception in your normal statemachine flows can be enforced with Play/CrossFade rather than trying to cover all the possible case and create a transitions spaghetti :D

    they are there to give flexibility to the system.

    Play and CrossFade are like dynamic transition which can be created at runtime and that live only for this frame.

    Performance wise they should behave exactly like normal transitions, so you shouldn't see an impact on the performance when you use them.
     
    theANMATOR2b and MrDude like this.
  4. Alakanu

    Alakanu

    Joined:
    Oct 17, 2015
    Posts:
    5
    Thanks for the explanation, so it's just different flavours of the same thing.

    You might wanna check out the ExitTime parameter on your transitions.