• 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 Peter Alexander · Dec 18, 2009 at 01:17 AM · animationperformance

Adding animation clips via script

I'm having a speed/memory problem when adding animations via script.

I have a character model that has 100+ animations spanning around 1800 frames. I've had trouble with Unity occasionally deleting all my animation clips when I reimport models, so I decided to add the animation via script, using animation.AddClip(...).

So now I have around 100 animation.AddClip(...) calls inside that character's Awake method, and on top of that I have up to 6 of these characters in a single scene.

The problem is that, on a 3GS, the game takes around 8 seconds to load those clips per character and also takes an addition 4-5MB, which kills older devices.

One way I could attempt to fix this is by just adding the animation clips in the Asset Import window like Unity expects you to, but I don't want to do this unless it's going to actually fix things, and there's also the side issue of us having a few different character models, all with the same animation frames; so I'd rather not have to duplicate everything for each one, but will do if it's our only option.

So my question is, will adding the clips via Asset Import fix my problem (and why?) and is there any better way to manage my situation.

Thanks in advance.

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

2 Replies

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

Answer by Jaap Kreijkamp · Dec 20, 2009 at 11:52 PM

If you don't have the performance issues when the clips are added through the inspector, you could try to add them using an editor script so you don't have to redo that every time when losing the connections after an import.

But, 100+ animations? It's quite a lot, don't know what you're doing but possibly you could reduce the amount by blending animations (separating the lower-body from the upper-body animations).

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 Peter Alexander · Dec 21, 2009 at 12:49 AM 0
Share

Thanks, I'll try the editor script.

Unfortunately there's not really any way we can reduce the number of animations, we simply need that many. A few of them could be blended, but there's still many more to add, so there's going to have to be some way of getting around it either way.

avatar image
0

Answer by nightstalker420 · Feb 03, 2013 at 02:11 PM

I had that problem on Android. The way I solved it was to not use animation compression and only call the animations (by script) as they were needed (duplicate, then delete the imported animations).

The script had to use Mathf.ABS rather than just Input.GetAxis and attached the script to the Tank rather than using Search("Player"). I also moved all the animations, after duplicated, to their own folder away from the models folder.

 if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.1)
       animation.CrossFade("rotateLeftAnimation");
  
     else  if (Mathf.Abs(Input.GetAxis("Horizontal")) > 0.1)
       animation.CrossFade("forwardAnimation");
  
    else
       animation.CrossFade("idleAnimation");

rather than just if (Input.GetAxis("Vertical")) > 0.1)

I posted a script yesterday that would handle all the animations and allow the private var so you can select each animation for each event here: http://answers.unity3d.com/questions/382738/how-to-start-in-animating-my-model.html

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

1 Person is following this question.

avatar image

Related Questions

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

Can an empty state in Animator cause performance issues? 1 Answer

Can i link an object to a moving object to save performance ? 0 Answers

Animation of terrain causes drastic performance drop (fps) 0 Answers

What's best (performant) way to animate light bulbs? 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