• 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
1
Question by Fattie · Jul 06, 2012 at 08:34 PM · animationanimationstate

Any guesses?! Reset an animation...

"Best way to stop and "reset" an Animation?"

Say you're playing an animation, so

 blah.animation.Play("spinTheLogo");

You want to stop the animation playing, and, you want it to simply return to the "original" "first" static state.

You want everything to be really clean so it is ready to use again with no problems, no other animations are disturbed, etc etc etc.

I've never really know the best way to do this.

I've seen and use code like either this...

 blah.animation["spinTheLogo"].time = 0.0;
 blah.animation.Sample();
 blah.animation.Stop("spinTheLogo");

or this ...

 blah.animation["spinTheLogo"].time = 0.0;
 blah.animation.Sample();
 blah.animation["spinTheLogo"].enabled = false;

But I really don't understand any subtleties between the two.

And there seems to be other ways to do it as well ... along the lines of using animationtate-something-zero ... and I don't understand those either.

In a word what is the usual, best, and correct idiom when you want to "have an animation simply stop immediately, and immediately return to the unperturbed state?, ideally causing no other trouble, leaving the animation easily usable in the future, and for example not disturbing any other animations running on the same object or subobjects?"

Thanks!

Comment
Add comment · Show 4
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 whydoidoit · Jul 12, 2012 at 08:01 AM 0
Share

Interesting question! I guess it depends if you want the time = 0 state to be affecting the object or you want no effect at all. Presuming that you want that first state then it's all about the interaction with Sample() I guess - which appears to apply the animation even if it isn't enabled (at least that's the implication from the script reference).

avatar image Bovine · Jul 14, 2012 at 06:21 PM 0
Share

$$anonymous$$oved to an answer... which I now see I could have done by clicking a button! doh

avatar image Bovine · Jul 14, 2012 at 06:30 PM 0
Share

The very left button on the comment that looks like refresh is actually convert to answer - I didn't see it until afterwards!

avatar image Fattie · Jul 14, 2012 at 06:31 PM 0
Share

A S T O U N D I N G !!!!!!!!!!!!!!!!!!!!!!!!!!! thanks!

2 Replies

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

Answer by Bovine · Jul 14, 2012 at 06:20 PM

When I've done this recently, I've gone with the latter of the two.

If you didn't disable the animation, then the animation will continue to play at whatever speed is set to.

Calling sample, I think would be necessary in order to ensure that the update occurs, as in my experience setting the animation to enabled = false will prevent any further updates.

Comment
Add comment · Show 5 · 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 Fattie · Jul 14, 2012 at 06:30 PM 0
Share

Thanks for that input Ian, it helps.

It's really amazing that there;s no totally decisive answer to this question. I mean, WTH !

avatar image Bovine · Jul 14, 2012 at 06:33 PM 0
Share

No worries - because I am playing animations when states change, I've taken to playing the animation simply by setting the old animation enabled = false, setting the weight to 1, setting the normalisedTime to however far through it needs to be and setting it to enabled. I also don't get the animation from the animation component each time - I've taken to doing this in Awake() caching a member of AnimationState - I'm hoping this is a good practise tbh... ?

avatar image Fattie · Jul 14, 2012 at 06:36 PM 1
Share

I simply don't know. I find the whole thing bizarre and I do not understand it ! Heh!

imagine you have say a long metal bar or perhaps a door or something.

imagine the animation is "rotate the bar through 90 degrees in X"

It just seems to me incredibly astounding, amazing, unbelievable - that you can't just do something simple to "return the bar to where it was"

Heh!

It makes me want to give up the whole scene and go back to writing romance novels for a living.

avatar image Bovine · Jul 14, 2012 at 06:38 PM 0
Share

Well I think if you set the normalisedTime to 0 and Sample() and then disable it, then that should work.

I have some dungeon doors in our iOS title that can start open and so I basically do that to move the doors to the open position, or rather, I set the normalisedTime for 1 on the open animation and sample and disable it. This is so it doesn't animate animate to open but is open from the get go of the scene loading.

avatar image Fattie · Jul 14, 2012 at 06:43 PM 0
Share

I really appreciate all the time you've taken, and will thoroughly investigate.

(At this stage I'm like "what the fuck's this 'sample' business guys?!" :-) )

thanks again !

avatar image
-1

Answer by Paulius-Liekis · Jul 10, 2012 at 10:01 AM

blah.animation.Stop("name"); is a better way to go, because it resets multiple properties (time, enabled, weight).

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 Fattie · Jul 10, 2012 at 11:19 AM 0
Share

that's unrelated.

Stop() stops it where it is. it does not actually "display" it in the original condition. Give it a try.

avatar image Bovine · Jul 12, 2012 at 07:02 PM 0
Share

I think Stop() will rewind the animation, presumably leaving the skinned mesh in the initial state of the animation. Whether this is what the OP wants I'm not sure, if they wish to return to the model state/properties as they were before any animation was applied (i.e. the X pose), then I'm not sure how you would do it.

http://docs.unity3d.com/Documentation/ScriptReference/Animation.Stop.html

avatar image whydoidoit · Jul 12, 2012 at 07:07 PM 1
Share

Yeah the Sample() in the question plays the frame against the current state without needing to enable the animation by the look of things.

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

9 People are following this question.

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

Related Questions

Can I make animations snap to a frame? 2 Answers

'speed' is not a member of 'Object'. when pausing animation 0 Answers

Error in AnimationState.cpp Line: 307 1 Answer

Using animation blending to create aim poses (3.5) 1 Answer

Moving Player only during part of an animation 1 Answer

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