So far I have been developing and testing on my PC. I dev on a Mac with a 4.2 GHz processor and 64 GB ram. This is a game being created for the Nintendo Switch and mobile devices, neither of which share the resources of my dev box. On my first test run of this game on mobile, it was fun to play but for several reasons ran into problems. In the upcoming posts, I will talk more about these issues. I will also discuss some of the workarounds I used to increase performance on mobile devices.
The issues I had are listed here and expanded upon later in the article and in future articles.
- Mesh Collisions are expensive (especially with overly complex geometry)
- Physics are expensive
- Object creation the easy way (instantiation vs pooling)
In my attempt to go fast I utilized Unity’s built-in collision polygon collider generation system. I am not bad-mouthing Unity, I love their products, but many of their out of the box solutions are not the most performant choices, especially if your target is mobile. The asteroids are pretty simple sprites, however, Unity decided to turn the spherical items into collision calculation nightmares. To approximate, the shape of each asteroid Unity created hundreds of nodes in the collision mesh. This meant for each physics step it had to determine if a collision happened on a very complex series of shapes. I discovered this issue after testing on my mobile device and not seeing the performance I wanted. I opened the profiler and Physics2D was the top user of resources. I created a script that would optimize the collider shapes but decided to go with a manual node reduction for the final product. I was able to get the asteroids down to a handful of nodes for each asteroid. The ships were an even worse issue. With guns and jagged edges all over the place, the generator had created nodes everywhere. I used the script again to reduce the nodes to a reasonable amount and then cleaned them up manually for the finished product. After these changes, I noticed a frame rate increase and a reduction of heat in my device.
Next week I will tackle the physics issues I created for myself.