Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. 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:
    4
    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,519
    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,552
    @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:
    4
    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.