понедельник, 16 сентября 2013 г.

Optimize performance in Unity3d: practical notes

(Russian post goes here)
I wrote an article in russian about unity performance optimization recently. In this topic I want to share some small, but efficient practical tips with you. Here we go:


  • if you're running out of memory, use proper texture compression. PVRTC is acceptable for iOS, DXT for android. And don't forget about mip-maps. I know, it gonna increase binary size by 30%, but it's worth it. Don't be so modest to limit max size to textures. 
  • If you don't need shadows in renderers (for example, in UI or something), just uncheck "Receive shadows" & "Cast shadows" options. They are always on by default.
  • Don't forget about batching. And yes, static batching allows much more than dynamic, so you don't move object, mark it as static. If you want to combine meshes runtime, use StaticBatchingUtility.Combine.




  • Take into account renderer settings, physics settings of project (Edit->Project settings)
  • Anti-aliasing, texture quality, shadows and vsync have many options. Just experiment with them to gain best performance/quality.
  • Uncheck layer collision checks you don't need to calculate.
  • If you don't really need physics, change fixed timestep.
  • Don't move static objects. 
  • Design your level, so your camera will not take a lot of objects, then camera culling will save a lot of frames for you.
  • Mesh collider checks are very expensive! It's better to use double-check technique: firstly make a capsule or box collider and check with it's collision, then check with mesh collider.
  • Lights. Know the difference between point & directional, use them properly. 
  • Cache  transform, collider, rigidbody. We use CachedMonoBehaviour in our projects and happy with that (P.S. From 4.1 Unity did a lot of work with GetComponent optimization, but CachedMonoBehaviour is still faster).
You may achieve better results if you know instruments you use. These tips are really easy to use and sometimes they give more performance than it's expected. Use it and know, premature optimization is root of all evil.


P.S. We are applying all this tips in game named technoball, so please free to try it and tell me what you think about it.
P.P.S We made a lot of work and prepared an awesome update, stay in touch!

Комментариев нет:

Отправить комментарий