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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Adjust Animation speed directly from Inspector

Discussion in 'Made With Unity' started by VoxelBoy, Sep 3, 2010.

  1. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    Hey folks,

    I spent the better half of today coming up with a solution to the following problem:
    You can't set animation playback speed directly from the Editor.

    You end up having to code the speed change into one of your scripts and that's not a scalable solution that can be applied to all the other GameObjects in your scene that have Animation components.

    You can read the detailed explanation of the solution over at my blog:
    Solve the System



    Instructions:

    • Download AnimationSpeedEditor.zip, which contains two script files: AnimationSpeedEditor.cs and OverrideAnimationSpeeds.cs.

      Place AnimationSpeedEditor.cs inside a folder named Editor in your project. Create the folder if it doesn’t exist. The other script file can be placed pretty much anywhere.

      Find or create a game object that has an Animation component attached, and add the OverrideAnimationSpeeds component to it. You should see the Animation Speeds foldout get added to the view of the Animation component.

      Open the foldout. If you have animation clips added to the Animations list of your Animation component, you’ll see sliders for each one. Use these sliders to set a starting speed for your animations. You can also use the sliders during Play mode and see the results immediately.

    Thanks.
     

    Attached Files:

    Last edited: Apr 14, 2011
    gterveen likes this.
  2. Pyroman311

    Pyroman311

    Joined:
    Aug 14, 2010
    Posts:
    87
    Cool stuff man. Thanks!
     
  3. gtjuggler

    gtjuggler

    Joined:
    Nov 13, 2008
    Posts:
    238
    Elegant solution. Cool.
     
  4. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Cool thing, but my scripts are all in JS :-(
     
  5. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    jrricky, I don't quite understand what you mean. The two scripts used in this solution only rely on each other. Your JS scripts should work fine alongside them.
     
  6. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Oh, thought it had to rely on my animation js code. Cool, I needed this. :)
     
  7. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Wow, this works wonders. Funny thing is, I was just having problems with the animations I have created over the weekend and the speeds I created them at werent syncing with each other and this just make the process very easy. Thanks!!!
     
  8. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    You are so very welcome! I'm just glad it's helpful to some people.
     
  9. chaudan

    chaudan

    Joined:
    May 14, 2010
    Posts:
    12
    Thanks a lot, its a really simple but incredibly useful tool!
     
  10. Disati

    Disati

    Joined:
    Oct 5, 2009
    Posts:
    111
    Thank you for making and sharing this! I'm sure this will help many people.
     
  11. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hey VoxelBoy, one thing I would like to ask is that, if I want to modify the speed by code to, for example, speed up a character, what would you recommend I do while still using this?

    Thanks
     
  12. VoxelBoy

    VoxelBoy

    Joined:
    Nov 7, 2008
    Posts:
    240
    The OverrideAnimationSpeeds script applies its overrides on Awake. So you can set your own speeds from code while still using this script if you do it anytime after Awake, such as Start or Update.
     
  13. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Hey, I came back to using your script, but I wanted to find out how I would call the script so I can change animations on the fly when I want through that script?

    Something like OverriderAnimationSpeeds.Change(animationname,speed);
     
  14. wheelbarrow

    wheelbarrow

    Joined:
    Sep 12, 2011
    Posts:
    174
    Ignore me, I got it sorted.
     
    Last edited: Sep 25, 2011
  15. Member123456

    Member123456

    Joined:
    Oct 17, 2012
    Posts:
    237
    This == BRILLIANCE!
     
  16. crafTDev

    crafTDev

    Joined:
    Nov 5, 2008
    Posts:
    1,818
    Zionmoose, not to plug my own Asset, but check out ASE too from the Asset Store. It's the same concept but I have made it more robust. It's also now on sale for $5.
     
  17. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,116
    thanks VoxelBoy this is brilliant!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     
  18. Power07RM

    Power07RM

    Joined:
    Apr 22, 2015
    Posts:
    12
    Many thanks! It's high time I got rid of my thousands of animation.speed lines! Well done Voxel
     
  19. Proto-G

    Proto-G

    Joined:
    Nov 22, 2014
    Posts:
    213
    Thank you for this!
     
  20. raiden

    raiden

    Joined:
    Feb 8, 2009
    Posts:
    333
    Very nice solution! Thank you for providing this to the community.

    -Raiden