1
\$\begingroup\$

I have created a project to reproduce the problem I'm currently facing. I'm running a simple unity animation that moves a game object and expect to be able to reset the gameobject position. This can be done by adding an empty animation, that (since it does not change anything) simply writes the default values, thus returning our gameobject to its original position.

But here is where things get complicated: if the animator gameobject is set inactive while the animation is running, new incorrect defaults values will be saved when gameobject is activated, and I am unable to reset my gameobject position.

To reproduce this issue, run the attached project: (Download from here)

  1. Change the stop method to "PlayEmpty"
  2. Hit Start Animation and watch the left "Hello world" text travel.
  3. While it is traveling, click Disable Text GO. The left text disappears.
  4. Click Enable Text GO and see the text comes back at its last location.
  5. Click Start Animation and watch the left "Hello world" text travel.
  6. Click Stop Animation - the text is returned to the position where it was when enabling the gameobject, rather than its original position.

Any help is welcome, suggestions on how to change the code to make the above scenario work.

Thanks, Yaniv

\$\endgroup\$
1
\$\begingroup\$

Creating an empty animation state does not write default values.

If you want a set of default values, you should explicitly set this default value in the state, even if this value were 0s.

Imagine if Unity were to assume everything to be their idea of a default - most animations would break. For instance, a rotating cube would jump back to world origin - we've never set its position.

If your case, simply create an empty state, assign it as your default state, and set your 'defaults' accordingly.

enter image description here

\$\endgroup\$

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.