Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Caproconaru · Nov 29, 2012 at 12:11 PM · animationperformance

Need help with a performance issue on my animation script

Hi

I just wanted to know if anyone can find the flaw in my animation script. The script is really not very long and not much is going on, but still I lose around 100 FPS when it is active

 var movingAnim : boolean = false;
 
 function Update()
 {
     Idle();
     if (Input.GetButtonDown("Forward"))
     {
         movingAnim = true;
     }
     if (Input.GetButtonUp("Forward"))
     {
         movingAnim = false;
     }
     if (movingAnim)
     {
         Move();
     }
     else if (movingAnim == false)
     {
         MoveToIdle();
     }
 }
 
 function Idle()
 {
     animation.Blend("idle8-motion");
     animation.Blend("flap");
 }
 
 function Move()
 {
     animation.Blend("8-motion");
     animation.Blend("flap");
 }
 
 function MoveToIdle()
 {
     animation.Blend("8-motion",0,0.3);
     animation.Blend("idle8-motion");
     animation.Blend("flap");
 }

I would really appreciate the help

thanks in advance

Comment
Add comment · Show 2
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 Tim-Michels · Nov 29, 2012 at 12:13 PM 0
Share

You shouldn't call stuff on your animation component every frame.

avatar image Caproconaru · Nov 29, 2012 at 12:46 PM 0
Share

Do you know a way I can call the functions without it being a Update?

1 Reply

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

Answer by Tim-Michels · Nov 29, 2012 at 12:59 PM

Your script should look something more like this:

 function Start()
 {
     Idle();
 }
 
 function Update()
 {
     if (Input.GetButtonDown("Forward"))
     {
        Move();
     }
     if (Input.GetButtonUp("Forward"))
     {
        MoveToIdle();
     }
 }
 
 function Idle()
 {
     animation.Blend("idle8-motion");
     animation.Blend("flap");
 }
 
 function Move()
 {
     animation.Blend("8-motion");
     animation.Blend("flap");
 }
 
 function MoveToIdle()
 {
     animation.Blend("8-motion",0,0.3);
     animation.Blend("idle8-motion");
     animation.Blend("flap");
 }

You don't even need the variable movingAnim as far as I know, the main idea is you only need to start an animation instead of calling the start of that animation multiple times.

Please let me know if this script works for you.

Cheers

Comment
Add comment · Show 5 · 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 Caproconaru · Nov 29, 2012 at 01:31 PM 0
Share

It "works" just as well as my previous attempts, but I just get a giant FPS-drop whenever this specific script is active on my object. I dont know if animation.Blend has a great effect on performance, but so few of them really shouldn't.

I have checked every other possibility for FPS-drop in my scene, but it is only when I dissable this script my FPS rises.

avatar image Tim-Michels · Nov 29, 2012 at 01:46 PM 0
Share

Well then I assume that your framedrop is caused by the animation itsself. Could you check if you play the animation automatically in your scene (without this script) if you also have this framedrop.

What kind of animation is it, is it with a skinned mesh? If so, how many bones and how many vertices are you using?

avatar image Caproconaru · Nov 29, 2012 at 02:03 PM 0
Share

The animation does not play automatically.

But you are right about the animation playing automatically cause FPS-drop (without the script).

The animation is a simple unity animation, making the object fly around in a 8-motion (like a fly) on the screen, so there is no skin involved.

So it could be that the model itself is too high-poly? I will come come back to you when I have redone the model, thanks.

avatar image Caproconaru · Nov 29, 2012 at 02:28 PM 0
Share

GREAT!

I did not really change much in the model but somehow a few tweaks here and there and now there is no drop in FPS at all.

Thanks a bunch, you have just become the shining light of my day :)

avatar image Tim-Michels · Nov 29, 2012 at 02:34 PM 0
Share

Allright, glad I could help ;)

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

11 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

Related Questions

Adding animation clips via script 2 Answers

Which is better: script or animation (which needs to change with scripting)? 1 Answer

how to make the animation stop after clip end ? 1 Answer

Unity animations not working 1 Answer

Check to see if animation is playing 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