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 BiznessMan · Dec 16, 2014 at 05:17 PM · androidperformance

Bad Android performance

Just started Unity and am trying to port one of my older games to it. I have only 9 sprites on screen and I'm getting really bad performance on my phone.

alt text

Statistics for reference. Any ideas? I'm testing it out on a Nexus 5

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 meat5000 ♦ · Dec 15, 2014 at 10:23 PM 0
Share

Building to a Philips C12? :)

Stats look fine. $$anonymous$$ust be a bad script.

avatar image BiznessMan · Dec 15, 2014 at 10:31 PM 0
Share

The only thing in my script is:

 'void Update () {   
             isGrounded = Physics2D.OverlapCircle (grounder.transform.position, radiuss, ground);          
              if (Input.Get$$anonymous$$eyDown ($$anonymous$$eyCode.Space) && isGrounded==true || Input.Get$$anonymous$$ouseButtonDown(0) && isGrounded==true) 
             {
                 rigidbody2D.AddForce(jumpVector, Force$$anonymous$$ode2D.Force);
             }
         }'

Also I just updated to the latest Unity and noticed my game went from 10mb to 18mb on Android

avatar image meat5000 ♦ · Dec 16, 2014 at 12:40 AM 0
Share

Add a null check to your OverlapCircle result. It's also probably expensive to do in Update.

Don't forget if statement parameters evaluate from left to right. Checking isGrounded twice is a waste of cycles, especially if its null.

Note that this function will allocate memory for the returned Collider2D object. You can use OverlapCircleNonAlloc to avoid this overhead if you need to make the check frequently.

Read the page again

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Baste · Dec 16, 2014 at 01:42 PM

Your fps is almost 3k. That doesn't sound like bad performance to me...

Anyways, you could improve the performance of the if-check slightly by doing this instead (it's more readable anyway):

 if(isGrounded && (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown(0)))

I'd actually expect the compiler to do that already, but the compiler we're sitting on is less than good, so that might not be the case.

Also, since you're not doing anything with the overlapcircle's returned results, simply use nonalloc overlap and send in an empty array. Allocating an array 2800 times every second will eat some memory.

 Collider2D[] results = new Collider2D[0];
 void Update() {
     bool isGrounded = Physics2D.OverlapCircleNonAlloc(transform.position, 2f, results) > 0;
 }

Finally, you could extract the whole ground check thing to a coroutine, and do it less often:

 bool isGrounded;
 
 void Start() {
     StartCoroutine(GroundCheck());
 }

 IEnumerator GroundCheck() {
     Collider2D[] results = new Collider2D[0];
     while(true) {
         isGrounded = Physics2D.OverlapCircleNonAlloc(transform.position, 2f, results) > 0;
         //Check 10 times each second instead of 2800 times
         yield return new WaitForSeconds(.1f);
     }
 }

 void Update() {
     if(isGrounded && (Input.GetKeyDown (KeyCode.Space) || Input.GetMouseButtonDown(0)))
         rigidbody2D.AddForce(jumpVector, ForceMode2D.Force);
 }

You should probably also put in a cooldown on the jump, as there will be quite a few frames after you've jumped that the player still haven't jumped.

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 meat5000 ♦ · Dec 16, 2014 at 01:44 PM 0
Share

This shouldn't have left moderation @Baste. It is an incomplete question.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Mobile game - should I reduce my vertex count? 1 Answer

Android Performance with 2d BoneBased Animation 0 Answers

Very slow game startup on android. 1 Answer

Extremely poor Android performance, even in simple scenes 0 Answers

Android performance VS IOS 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