3
\$\begingroup\$

I'm running into a situation where my frame rate drops from 70 FPS (on my desktop computer) down to 5 FPS (on my iphone) and I'm trying to understand why. At the moment, I'm only drawing simple tiles, with box colliders attached to them, on the screen...

enter image description here

I've read that colliders are very expensive to have and I have 2400 of them on the screen at any given time. My questions are...

  1. Do you think it's the number of colliders that are causing the slowdown?
  2. If so, what are some ways I can optimize this?
  3. If not, what do you think the problem is?

Thanks so much for your wisdom!

Also, it's worth noting that I'm using 2D Toolkit in Unity for drawing.

UPDATE: I just removed all the colliders in the scene and I'm still experiencing the slowdown. Your thoughts?

\$\endgroup\$
5
  • 3
    \$\begingroup\$ 1. yes, 2. don't have so many colliders, Are you trying to achieve something in particular? Also note not a good measurement between desktop and phone (different systems), if you wish to benchmark start of with no colliders and add more till 2400 to compare the equiv speed differences. \$\endgroup\$ Commented Aug 8, 2012 at 17:24
  • \$\begingroup\$ ok, so it's actually not the colliders. I just removed all the colliders and the i'm still experiencing the slowdown. Your thoughts? \$\endgroup\$ Commented Aug 8, 2012 at 18:00
  • \$\begingroup\$ Removing the colliders will make performance worse right? I mean your intent is to optimize collision...or what? Have you considered checking the settings for your iphone project? \$\endgroup\$
    – Sidar
    Commented Aug 8, 2012 at 19:19
  • \$\begingroup\$ When exactly do you experience the slowdown, please describe your setup. \$\endgroup\$
    – jonas
    Commented Aug 9, 2012 at 7:56
  • \$\begingroup\$ What was the cause of your slowdown then? \$\endgroup\$ Commented Feb 5, 2017 at 15:21

3 Answers 3

1
\$\begingroup\$

Any time slowdown is an issue, the important thing to do is test and measure. There are a variety of tools available to do so, but even without a profiler you can do this simply by measuring the time different sections take via things like System.Diagnostics.Stopwatch (if using C#) or even the base unity Time information.

You've already determined the colliders, while very numerous, don't seem to be the cause of the performance drop between systems so see if you can rule out other large sections of your code, either by timing or by simply commenting them out and testing framerate again. Chances are you'll find a big chunk somewhere that suddenly brings the framerate up when you leave it out and you can then repeat the process inside that chunk until you've found the offending section.

\$\endgroup\$
0
1
\$\begingroup\$

I'm new to this, but it would seem to me that if things aren't working, you should try something else. So maybe try a fewer colliders?

EDIT: You also might try using a fixed frame rate, like described here: http://obviam.net/index.php/the-android-game-loop/ Maybe you can fix the framerate so it stays high

EDIT2: Maybe you have a memory leak? This article talks about that possibility on iOS: http://www.cocos2d-iphone.org/forum/topic/6641

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Good answers get upvotes. Not answers that ask for upvotes. This doesn't address the original question very well and it doesn't address the updated question at all (which was updated before you answered) \$\endgroup\$
    – House
    Commented Aug 8, 2012 at 18:17
  • 1
    \$\begingroup\$ oh, thanks for the info - I'm pretty new to this, I'll try to do a better answer with my next one \$\endgroup\$ Commented Aug 8, 2012 at 18:18
  • 1
    \$\begingroup\$ Bob, you can edit this answer to improve it, no need to wait until the next one. Additionally, you're free to ask a question before getting 10 points. You'll just have to make it simple without all the images and links you want. If it's a good question it'll get upvoted and you'll have enough rep to update it with images and links. \$\endgroup\$
    – House
    Commented Aug 8, 2012 at 18:20
  • 1
    \$\begingroup\$ Oh, ok - I've been trying to help people out with their questions by trying to find good resources for them online. Thanks for the tip! \$\endgroup\$ Commented Aug 8, 2012 at 18:29
0
\$\begingroup\$

I think Unity uses Box2d? IIRC from an old read box2d uses some sort of spatial trees so that inactive colliders should not consume much CPU power.

My guess is, check your draw calls which are very often the cause for lags on mobile, make the colliders invisible and see if it helps in your frame rate, good luck.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .