Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
0
Question by ivarhill · Mar 11, 2019 at 05:48 AM · animationanimatorloopsetactive

Can't play animation after setting GameObject to inactive and back to active again

I have an UI element which has an Animator component attached with a simple looping animation that fades it in and out.

This UI element needs to be turned on or off on multiple occasions, so I have a script that disables it as needed using SetActive(false).

However, though it animates correctly at the start of the game, as soon as I've set this to SetActive(false) and then SetActive(true) again, or if any of its parent GameObjects go through the same process, the looping animation stops and I cannot figure out how to make it start playing again.

I've tried manually playing the state with .Play("statename"), as well as manually turning the actual Animator component on and off again with no luck. This is an extremely simple application, so I was hoping I'm missing something obvious here...


Edit: As mentioned in the comment chain of the original post, it turns out that the cause is the UI window setting Time.timeScale to 0 to pause the game while open, which naturally also pauses the animation. Can this be overridden or circumvented somehow? I'll need to use these kind of UI animations while the game is paused, and setting the timeScale to 0 seems like the most reliable way to do this.

Comment
Add comment · Show 9
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 xxmariofer · Mar 11, 2019 at 08:53 AM 0
Share

is your animation connected with you default state in the animator?

avatar image ivarhill xxmariofer · Mar 11, 2019 at 02:56 PM 0
Share

Yes - this is what it looks like: alt text

The animation itself has loop time set to true.

animator.jpg (63.7 kB)
avatar image xxmariofer ivarhill · Mar 11, 2019 at 03:25 PM 0
Share

when you are in playmode what happens? the flash animation should be played. the blue line that shows which animation is being played is not even appearing?

Show more comments

5 Replies

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

Answer by ivarhill · Mar 11, 2019 at 04:23 PM

Setting this as resolved since the issue is separate from the original question. Thanks to @xxmariofer for suggestions!

Comment
Add comment · Show 2 · 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 xx12animedude12xx · Feb 23, 2021 at 11:22 PM 0
Share

he y man i'm dealing with the exact same problem as you. Did you manage to solve the problem and if so, how?

avatar image xxmariofer xx12animedude12xx · Feb 24, 2021 at 08:22 AM 0
Share

check the comments of the question for the full discusion but his issue was setting time.scale to 0

"That's a good idea! I did some testing and I think I finally found the root cause - while the code to open the UI window itself runs, it sets Time.timeScale to 0 to pause the game, which also pauses the animation. Obvious in hindsight...

Is there a good way to get around this? I need to pause the game while the UI is open, but I also need animations like these to play, so maybe there's a different method entirely that makes sense."

avatar image
2

Answer by drHogan · Oct 24, 2019 at 10:27 AM

You probably solved it by now, but in the inspector you can change to Unscaled Time the animator update, this way it will not be influenced by the game timescale.

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
0

Answer by cs120319992 · Mar 11, 2019 at 03:51 PM

Try to enable and disable self animator on object.

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 ivarhill · Mar 11, 2019 at 03:57 PM 0
Share

As in set the animator component to disabled and enabled again once the GameObject has been activated? I've tried this-

         Animator flashAnimator = flashEffect.GetComponent<Animator>();
         flashAnimator.enabled = false;
         flashAnimator.enabled = true;
         flashAnimator.Play("flash");

But it doesn't seem to make a difference. For reference, this is what the Animator looks like while running: alt text

It just sits still with the blue bar at that position and does not move at all.

animator2.jpg (22.7 kB)
avatar image
0

Answer by YiYiBaBa · Mar 11, 2019 at 04:12 PM

link text

Add the overcondition and try it

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
0

Answer by Fingall · May 31, 2021 at 08:05 AM

you shoude use this: if (isActiveAndEnabled) { animator.CrossFade(acname, 0f, -1); }

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

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.

Follow this Question

Answers Answers and Comments

274 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How can I reset a non-looping animation? 0 Answers

Animation keeps playing even with "loop" deactivated. 1 Answer

Loop Time through Script 2D 4.3 1 Answer

Loop Animation 1 Answer

Animations in the animator not looping 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges