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

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.