Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Join us on Dec 8, 2022, between 7 am & 7 pm EST, in the DOTS Dev Blitz Day 2022 - Q&A forum, Discord, and Unity3D Subreddit to learn more about DOTS directly from the Unity Developers.
    Dismiss Notice
  3. Have a look at our Games Focus blog post series which will show what Unity is doing for all game developers – now, next year, and in the future.
    Dismiss Notice

Animation Component can only play the animation again when it has finished playing that animation.

Discussion in 'Animation' started by axxelart, Jul 30, 2022.

  1. axxelart

    axxelart

    Joined:
    Jun 28, 2020
    Posts:
    15
    Hey everyone!
    Recently, I've encountered an issue with the Animation component. So I'm trying to fire an event where the animation component plays an animation, multiple times (in a time interval less to the duration of the animation) but, the animation component REFUSES to play the animation again UNLESS the animation has finished playing from its initial play. Anyone can help on that regard?
    Thank you in advance!

    PS: The animations are being played using the Animation.Play() function through script.
     
    Last edited: Jul 30, 2022
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,184
    I've never really used the Legacy Animation component, but the way I designed Animancer was to have the Play method not automatically restart an animation that is already playing so perhaps the Legacy Animation component works the same.

    I believe the way you access states in that system looks something like this:
    animation["ClipName"].time = 0;
     
  3. axxelart

    axxelart

    Joined:
    Jun 28, 2020
    Posts:
    15
    Ah, I see, well recently I figured it out by having the Animation component stop BEFORE it plays again. It worked that way. Unless I could just use your method and set the time of the animation to 0 again.
     
  4. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,184
    I would expect Stop to have a bit larger performance cost than just setting the time of one state, but it would be very small either way and is unlikely to actually matter.
     
  5. axxelart

    axxelart

    Joined:
    Jun 28, 2020
    Posts:
    15
    Alright, got it. Thanks for the help!