• 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 dingben · Feb 21, 2011 at 01:18 PM · animationvisible

Animations - Animate only when visible

Unity 3.1.0f3 (54715) ... (not doing 0f4 yet, too much to do in project folder)

Question: On animations, is there anything else that needs to be setup along with 'Animate only when visible'?

One main camera child of FPS or vehicle.
Animations are all generated with the Unity Animation tool.
'Animate only if visible' is checked.
Docs: 'When enabled, the currently playing animation will not play if the object is not visible on the screen.'
All works beautifully, except for one snag...

I have emitters which stop emitting when cam is not on them. All good.
I can tell because as I turn away from the emitter and turn back to bring it in cam range,
I can see the emitter(s) kick back in.

When I do the same test with animations, I can see that the object has continued to progress
on its course
, the animation does not stop, 'IsPlaying' returns true always.

T.y. for your help.

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

1 Reply

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

Answer by Bunny83 · Feb 21, 2011 at 02:18 PM

"Animate only if visible" just reduces performance cost. The animation will play normally but the animation curves are not applied. eg. a skinnedMeshRenderer needs a lot of transformations on each bone when animating a character. If it's not visible you don't care if the bones are transformed or not.


EDIT:

Ok, a bit more in detail:
Animate Only If Visible is affected by all cameras. If at least one camera can "see" the object it will be animated. That includes the scene-view camera in the editor (that's the edit view)!

If you create an animation in Unity that will move a object along the x-axis from 0 to 200 in 10 sec. The object will move slowly from 0 to 200.
Let's say you don't look at the object when you start the game, but you set the animation to "Play automatically". That means the animation is started right at the beginning and the animation time runs, but the object is not moving. If you look at the object after 3 sec. the object will jump suddenly to 60 on x-axis and is animated towards 200.

You should not use animate only if visible on moving animations because the object will never move until the object itself comes in view. In the case your camera is placed at x 100 (in the middle of our animation way) and you look at the end point (x 200) the object will never animate even if the time is 5sec+. The calculated position would be in view but the object is not in view at the moment and therefore not updated.

For stationary character animations like "idle" that's not a problem. The character is moved independently from animations. If he's not in view the idle animation loop will be looped but not updated.

Now a little bug:
Animations that "Loop" or "PingPong" are not a problem the time loops fine and when it comes in view it jumps in at the current time. But animations with wrapmode Once or ClampForever have a little problem. When the time reaches the end and it's not in view at that moment it will not stop the animation. In ClampForever you want this, but the object isn't even updated to the last position if it's in view again.

That's why i recommend to use this option on looping, stationary animations only.

If you actually want to pause the animation when it's not in view, you have to do this yourself.
Something like:

// C# void OnBecameVisible() { animation["TestAnim"].enabled = true; animation["TestAnim"].weight = 1.0f; }

void OnBecameInvisible() { animation["TestAnim"].enabled = false; animation["TestAnim"].weight = 0.0f; }

If you still want to control the animation manually you need to handle this yourself and create some custom animation managing.

I'm not sure if AnimationEvents fire if animate only if visible is on. I don't use them. Try it yourself ;)

good luck and i'll hope that clears up your questions.

Comment
Add comment · Show 4 · 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 dingben · Feb 22, 2011 at 09:56 AM 0
Share

Thank you for your answer. Pardon my inexperience, but I am not clear on what you exactly mean. $$anonymous$$y understanding is that if the animation plays, it is due to the animation curves definition. If I define an animation without keyframes nothing plays. It only plays once a curve contains keyframes. Thus what do you exactly mean it will play normally? and it won't use the animation curves? ...and secondly, why does IsPlaying always return 'true'... for that tmatter how about events? once I add events, how will that behave based on 'Animate only if visible'?

avatar image dingben · Feb 22, 2011 at 10:06 AM 0
Share

is there other documentation besides the Unity Help that covers more detail?

avatar image Bunny83 · Feb 22, 2011 at 01:28 PM 0
Share

I've edited my answer.

avatar image dingben · Feb 23, 2011 at 08:42 PM 0
Share

Thanks... Amongst other info you provided, your paragraph: "Let's say you don't..." was a tidbit I was starting to assume... it plays but it does not render, that way it stays with the progress of the animation and can resume at any point with the rendering. Bouncing everything you said with yet one more reading of the Unity existing docs, it is starting to make more sense now. Wish they had worded it: '...it plays but does not render...' ins$$anonymous$$d of '...it does not play...! ...and that answers why 'IsPlaying' returns true even if off viewport. Thanks again. ...have credited you

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

No one has followed this question yet.

Related Questions

Can the animation editor create local rotational data? 3 Answers

AnimationEvents firing if animation not visible? 1 Answer

Adding animation clips via script 2 Answers

Make bones visible when playing 2 Answers

Multiplayer animation only visible for my character 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