Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
2
Question by sandworm · Sep 12, 2011 at 11:17 PM · animationperformancelagcpuspike

Animation.RebuildInternalState spike

Hey guys, I keep getting CPU spikes which I've tracked in the profiler to Animation.RebuildInternalState. What can be done about this?

Comment
Add comment · Show 3
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 sandworm · Oct 01, 2011 at 09:40 PM 3
Share

UPDATE: I was just at Unite 11, and I asked the Unity developers there. They said that it's a known issue, and it gets called on enable or disable of the animation component (or the object). They recommended pooling your objects, rather than instantiating them in-game, and leaving them in an active, offscreen state. With this and a few other improvements, I got my game from 35fps to ~55.

Hope it helps!

avatar image Bovine · Jul 08, 2012 at 08:19 AM 0
Share

@sandworm can you expand on your work-around - we have a similar issue with DrawVBO and CullAllTerrains spiking, despite otherwise smooth performance and no GC we can detect happening at that time?

avatar image Bovine · Jul 09, 2012 at 11:56 AM 0
Share

We have a LOD system for our skinned meshes (NPCs) that shows the nearest skinned meshes up to a certain number 5 at present and then drops to a non-skinned mesh that bobs about - a low lod in fact of the skinned mesh. This was working really well, but in profiling our game we've found that we get this spike in Animation.RebuildInternalState().

Our LOD system disables the animation on the skinned mesh so that it doesn't run while the mesh is hidden (maybe I don't need to do this, I will check), so I tried moving the objects behind the camera, but we had probably the same level of spiking if not worse, so setting an animation active may cause this function to run and spike, but moving the animation off screen does NOT fix it for me.

We're running on iOS and on a 3G S this spike can be as big as 200$$anonymous$$S - it's putting 3G S as lowest spec hardware under threat tbh. :o(

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by mehware · Oct 01, 2011 at 07:38 PM

I am having the same problem with Animation.RebuildInternalState too. I have it take up 13% of the time and 5ms of time. I don't know what keeps calling it? Any ideas.

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 Bovine · Jul 09, 2012 at 12:26 PM

I was just checking this out over lunch - if I don't disable the animation component and I do disable the skinned mesh renderer, then it looks like my spikes have gone away with two caveats: I've not tested this on the 3G S I was using yesterday; on the 4S I did see a massive ~300MS spike in RebuildInternalState() very early on in the level (i.e. within the first few seconds) but that seemed to be the only one, probably just as a whole bunch of animations hit the camera frustum for the first time.

So my suggested solution - the one we are now using - is to set the skinned mesh renderer enabled to false and not both disabling the animation or moving either object off screen. Of course a solution that moved the object offscreen and disabled the Renderer may prove even more efficient...

I don't have a solution tested yet for the huge spike I received, but perhaps I can align the animations in front the camera for a second with all lights off/texture occluding them and then move them back to their proper positions. Feels like a bit of a hack though...

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 Bovine · Jul 09, 2012 at 07:51 PM 0
Share

It looks like the moment a (skinned) animation is considered by the game it will RebuildInternalState(), so while my solution is sound enough, whenever a skinned mesh is going to be rendered for the first time there will be a spike. Our LOD system runs smoothly on a 4S with 60 mobs being considered and simply disabling the skinned renderer.

On the 3G S I am testing with 60 is too many but 30 seems to be acceptable. Both suffer a lot of stuttering early on (first 5-10 seconds) but this test level is completely open and the 60 mobs are tightly packed, in something like two phalanx, so it's probably an artificial grouping. Still I would rather this be called before the game renders a frame even and the player wait longer before the level starts, maybe a second or two all told.

I am thinking of ways to force it to happen, starting with seeing if I can call the method, perhaps by reflection even?

avatar image Bovine · Jul 09, 2012 at 09:32 PM 0
Share

The slightly hacky approach of spawning all the NPCs in front of the player, behind the loading screen, waiting a few frames (okay a second AT$$anonymous$$) and then shifting them back to their spawn location, seems to eli$$anonymous$$ate any visible spike from RebuildInternalState() on my iPhone 4S.

I will check on the 3G S which was struggling more, when I can acquire it - $$anonymous$$rs Bovine is in bed and she is the keeper of said device ;o)

avatar image
0

Answer by anniyan137 · Nov 20, 2013 at 06:36 AM

I too was getting this problem. After a LOT of experimentation, I have understood it to have something to do with "attaching unnecessary animations". What I mean by that is that I used to attach all animations used by different AI types in the same prefab and changed their material at runtime and defining their type by code.

Just for the sake of trying I segregated the different AI types into their own prefabs and minimized loading of unnecessary animations. I was relieved to see that this helped; substantially.

I don't know if this is the right solution, but I am no longer getting that CPU spike on Animation.RebuildInternalState.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Adding animation clips via script 2 Answers

What kind of performance impact does looping anmiations have on a game? 1 Answer

Multiple Animations cause Lags and Freezes on Unity iPhone? 2 Answers

Is 2d animation better for performance over particle system? 1 Answer

Can an empty state in Animator cause performance issues? 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