Last year I was working on a big RPG project as part of my studies. It looked great and ran fine on PC but didn’t run so well on the ps4 dev kit. After a lot of tweaking I got it from something stuttery to something smooth on ps4. If you want a quick look at what we did:
This is by no means a complete optimisation guide, but it tells you how I optimised our game.
One of the biggest drains on performance was the size of textures. We left all of our textures at their default resolution, which was:
- Max Size: 2048
- Comression: Normal
In the end, most of the enemies textures were:
- Max Size: 256
- Resize Algorithm: Mitchel
- Compression: Low Quality
You couldn’t tell the difference. Try lowering the quality and see if others can spot the difference.
If you have objects that aren’t using their animators, remove the component. They still use up a lot of performance even if the object isn’t animated.
If at all possible, avoid ever using Unity Terrain. We lost so much perfomance because of this.
Lower poly models can help, but don’t go too crazy. We actually ended up increasing the tri’s on a number of our plant models. It partly depends on how many objects are active in the scene at once.
Combining meshes can also apparently increase performance, but I’ve never tried this. Tools I was recommended to look at for that:
- Mesh Combine Studio
- Mesh Baker
Lighting And Rendering
We had lots of point lights which was terrible with forward rendering, the Unity default. Deferred rendering gave a big improvement in performance and lighting quality.
Depending on how you do your lighting and other factors deferred rendering isn’t necessarily for you, so start doing research into choosing a rendering path.
Destroying lots of objects regularly can be expensive, as well as creating lots of objects. If you’re doing this, research object pooling which is a method of creating a whole bunch of objects at once and then re-using them.
Mainly useful for things you have lots of copies of, like bullets or coins.
Trigger Events & Collisions
Remember that the player isn’t the only thing that can trigger OnTriggerEnter events. If you have an object like a coin sitting inside some sort of trigger, it could be firing lots of OnTrigger events, especially if you have lots of coins sitting inside triggers.
Consider making it so that such objects can’t interact, or deactivating objects beyond a certain distance.
Moving lots of colliders can be expensive, so find ways to avoid it. We had hundreds of coins rotating by a script that also rotated their colliders. This meant Unity was constantly doing maths to recalculate the colliders and caused huge lag.
- Be careful with your scripts and avoid checking too many things that don’t need to be checked, or running too much code that doesn’t need to be running.
- Deactivating objects that are far away from you, including lights, can save on performance.
- Find the settings that are best for your particular project.
- Don’t stress too much early on in the project about optimisation – you can do it closer to the end, but keep it in mind.
- Be careful what you download from the asset store – there’s stuff on there that isn’t well made and can harm your performance.
- Remember that your game generally runs better in build mode than it does in editor.
- Debug messages and other Debug functionality running in editor can slow your game down a lot, especially error messages, so don’t forget to turn Debug messages off.
- A lot of this is what worked for me, but every game is different. Learn to use the Unity Profiling Tool to find out where your games bottlenecks are. If you see something you don’t know what it is, try Googling it.
That’s all I’ve got for you in this guide, but if I learn other optimisation techniques later I’ll be sure to save them. If you have any of your own you want to share, post a comment below.