Here are some tips for optimising your unity games that I discovered whilst making Get A Grip. They focus on development for mobile but many can be applied to any game!

Use the profiler

The profiler is the first thing to head to if experiencing performance issues – it gives you an overview of where your resources are being spent and if there any obvious problems. The sections are broken down into CPU usage, Rendering, Audio, GPU, Memory and Physics. When creating a mobile game you will want to profile the game running on your phone rather than your desktop. A guide for setting up your mobile device to hook in with the Unity profiler can be found here on the Unity website. As of Unity 5 the profiler is now available for everyone to use!

Profiler

It looks more complicated than it is

Batch all of the things!

For an explanation of what a drawcall is see the Unity website. It’s generally a good idea to keep the draw calls as low as possible. One of the ways you can do this is by using batching. Models that batch have to share the same material, in Get A Grip we managed to get every model in the game onto one material since the “textures” are just lots of block colours. This is by no means a common approach and is more of an experiment that happened to work well for us.

Textures

Best texture I ever saw

Dynamic batching

Dynamic batching will run automatically as long as you satisfy the requirements. The full list can be found on the Unity website. The main requirement we had to work around was “making sure your models contain less than 900 vertex attributes in total”. To accommodate this we broke our larger meshes up into several pieces and exported them individually. We had to make sure our meshes were under 300 verts each since they used normal and tangents which count towards vertex attributes. Once the meshes were imported we snapped them back together inside Unity.

Before and after snapping together

Before and after snapping together

Static Batching

Static batching doesn’t have a vert limit and will work as long as you mark a mesh as “static” and they all share the same material. Obviously the mesh must also stay static (No movement or scaling). Static batching wasn’t an option for us with Get A Grip since background elements were moving and the tree is procedurally generated which wouldn’t have worked if the meshes were static.

Make an FPS counter

It is a good idea to make your own FPS counter. Unity’s built in FPS counter in the stats window is inconsistent and can only be viewed when running your game in the Unity editor. This means you can’t view your FPS on a mobile device. There are several guides for implementing your own FPS counter online such as this one.

Use the stats window

But you just told me the FPS it provides is rubbish! Whilst this is true the stats window contains lots of valuable information such as; number of draw calls, batched draw calls, polygon counts and texture memory usage. For Get A Grip we started to get framerate issues if we exceeded around 30k verts / 20 draw calls. This number will vary quite a bit depending on the game however so don’t take it as gospel. We were targeting lower end devices, top end devices can support a fair amount more draw calls and verts now. It’s still a good idea to keep the requirements as low as possible though.

Stats-Window

This window will be your best/worst friend when making a mobile game

That’s it for part 1. In part 2 we will cover even more tips for optimising your Unity games!