• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
8
Question by pauldstewart · Feb 17, 2011 at 11:19 AM · animationpause

Pausing an animation

I don't see a straightforward way to pause an animation. Presumably I first have to log the current frame when I click a button or press a key, and then start the animation again from that frame.

The question being really, how do I get the current frame of an animation? Or is there a better way to pause an animation?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
14
Best Answer

Answer by TheDemiurge · Feb 17, 2011 at 11:37 AM

AnimationState

From the docs under Animation: (no example under AnimationState)

// Make all animations in this character play at half speed
for (var state : AnimationState in animation) {
    state.speed = 0.5;
}

so speed = 0 will pause it :)

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pauldstewart · Feb 17, 2011 at 11:40 AM 0
Share

Thank you......

avatar image
22

Answer by Setsuki · Nov 26, 2012 at 10:46 PM

speed = 0 doesn't work in my case, and I have many animations thaat can be playing. In my case, I litteraly want my character to freeze, so I simply used

 animation.enabled=false;

Worked like a charm.

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image petey · Jan 02, 2014 at 01:19 AM 0
Share

Awesome thanks for posting this! Way simpler than the crazy stuff I was trying to do :)

avatar image Wessels · Dec 15, 2014 at 09:28 AM 0
Share

When using animation.enabled=true will it start the animantion again or continue where it was stopped?

avatar image georgepiva · May 19, 2015 at 02:48 PM 0
Share

@Wessels The answer is yes. It will continue from where it stopped.

avatar image BEFaughnan · Jul 07, 2016 at 08:28 PM 3
Share

When I use this method the animation skips ahead where it would have been when turned back to true. Is anyone else experiencing this?

avatar image Brumpet · Jul 30, 2016 at 09:49 PM 0
Share

Just used my one and only rep point on this, dont know how to get them, and probably will never get another. Seriously, this works so well, ;D;D;D

Show more comments
avatar image
6

Answer by Hritik-Mahirrao · Jul 01, 2015 at 05:44 PM

You can use 'enabled' property to stop/pause animations

animator.enabled = false;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Madhur26 · Jun 26, 2017 at 07:57 AM

using System.Collections; using System.Collections.Generic; using UnityEngine;

public class pausescript : MonoBehaviour {

 public bool paused;
 // Use this for initialization
 void Start () {
     paused = false;
 }
 
 // Update is called once per frame
 void Update () {
     
 }

 public void Pause(){
         paused = !paused;

     if (paused) {
         Time.timeScale = 0;

     } else if (!paused) {
         Time.timeScale = 1;

     }

 }

}

This worked for me.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image remingtonspaz · Apr 04, 2019 at 03:16 AM 1
Share

This is incorrect. This pauses the whole game ins$$anonymous$$d of just the animation.

avatar image highpockets remingtonspaz · Apr 04, 2019 at 08:25 AM 0
Share

If the animation is on its own layer, setting the weight to 0.0f is an effective approach and also lerping to zero can have a smoother effect.

avatar image remingtonspaz highpockets · Apr 13, 2019 at 04:07 PM 1
Share

Sure, but I don’t see what that has to do with this answer?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

pause animation when two objects is colliding and resume when they're not colliding without rigid body? 0 Answers

Pause an animation with a button 1 Answer

Adding animation clips via script 2 Answers

Creating a play/pause button for animations. 0 Answers

Pause Animation 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges