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

Making a Sprite animation loop just once

Discussion in '2D' started by hunter9000, Apr 1, 2014.

  1. hunter9000

    hunter9000

    Joined:
    Mar 6, 2011
    Posts:
    5
    I have a spritesheet that I've set up as a 4 frame animation. It's a short explosion animation, and I can instantiate one in my scene just fine. The problem is that the animation keeps repeating indefinitely, and I want it to just play through once and then destroy it. I can't find anyway to set it up to stop after looping once. I also can't find any kind of callbacks that I can hook into to get notified when it's done and destroy it manually. Anyone know how to accomplish this?

    Thanks!
     
  2. Bivrost

    Bivrost

    Joined:
    Mar 26, 2014
    Posts:
    80
    Just to make that clear: Unity comes with an extensive documentation. ;)

    This might help you: Animation.wrapMode. In case you are using (or want to use) an Animation State Machine you could also solve this by defining an Animation Transition with an Exit Time condition. It's pretty straight forward.

    The callbacks you are looking for are called Animation Events and allow you to call functions in your object's script.
     
  3. kunterbunt_kluges_design

    kunterbunt_kluges_design

    Joined:
    Jan 12, 2016
    Posts:
    3
    Another way is making a transition to a one-sprite animation.
    If you want to destroy the GameObject when animation ends, you can add a script to it in Animator->State->Add Behaviour.
    Un comment the "OnStateExit" procedure and add "Destroy(animator.gameObject);" on it.
     
  4. zain3x

    zain3x

    Joined:
    Oct 13, 2017
    Posts:
    1
    in Animator window, click twice your animation capsule. You'll found loop checkmark.
     
    monxterz and lunaeight08 like this.
  5. lunaeight08

    lunaeight08

    Joined:
    Oct 29, 2020
    Posts:
    10
    Thank you for this!
     
  6. davidw

    davidw

    Joined:
    Jan 6, 2013
    Posts:
    1
    wondering why we have to click twice on the animation capsule, why isn't that information shown in the properties window by default? Just wondering what else I can find by double clicking on other stuff in Unity