Play now

Показаны сообщения с ярлыком fps. Показать все сообщения
Показаны сообщения с ярлыком fps. Показать все сообщения

воскресенье, 21 июня 2015 г.

Unity optimisation tips


My previous article was in russian. So this I decided to write in English. 

Maybe you have heard or even already played Alco Invaders on PC. 

But we also make Alco Invaders for mobiles. We tested it on wide range of devices:

-Kindle Fire 1,
-HTC One,
-Nexus 4, 
-iPhone 4S, 
-iPad mini 2, 
- Galaxy Tab 4 
- and even tablet Windows 8.1.

So on all this devices we tried to achieve 50-60 fps performance. And we did it! And on almost all devices graphic level is the same as in PC. Except Kindle Fire - it doesn't support bloom :)





When we only started to work on game - performance was horrible. 15-20 fps on Android. But we decided make good picture in any way. 




In my previous article I have wrote about core elements of optimisation. And this about polishing optimisation. Secret tricks, which can save 20-30 % of performance.

1. Never use .transform in circles

It was a great surprise, when I discovered this thing. But in Unity .transform = .GetComponent<Transform>().

Example is Bullet script 
https://gist.github.com/Oxygamer/20100d06e11a8494042d

And getting component cost much in circles. In my tests it save almost 12 % of performance. So, make variable of type Transform and assign it in the Awake() function.


2. Vector3.Distance() is expensive enough.

The reason - is Mathf.Sqrt() inside this function.

So if you can - better use predefined table of distances or calculate it not in Update().
I used such trick in my Hexagon particle system. 

If you have some kind of grid - calculate distances between all elements and write it to simple array float[].

It saves ~ 10 % performance.




3. Almost all physical is expensive.

Maybe it's obvious, but you can forget about physics of explosion, or bullets. Check all them and try not use much physical objects in one time.



4. Use delayed trash cleaning.

For this purpose better use .SetActive(false), store object to some list, and Destroy() it in pause or end of level. It depends of your game type.

5. Shaders - use VertexLit if you can.

Maybe it's not huge difference between VertexLit and Diffuse, but Specular cost much. The reason is per pixel light rendering in Diffuse/Specular shaders and per vertex in VertexLit.




6. Use Dictionary<key,value> for prefab storage.

It's useful when you searching object with some name or type.  For example you can use List<> for Editor, and then put all this prefabs to Dictionary<> on game start.

As example - Object Storage script

https://gist.github.com/Oxygamer/c93d958ae138aef607b2

P.S

Hope this tricks and techniques will be useful for you ! If you have some questions - write it in comments. I will help with gladness :)

пятница, 23 августа 2013 г.

Секреты анти-оптимизации в Unity или как достичь 10 FPS

  1. Двигайте static object, как можно чаще
  2. Кому нужно сжатие текстур? Только не мне !
  3. Текстурный....атлас...что это ?
  4. Debug.Log EVERYWHERE !!! В каждой строчке кода! в каждой функции Update !
  5. Поместите побольше кода в Update ()   !!!
  6. OnGUI anything  используйте стандартный OnGUI .
  7. Ты имеешь Mesh Collider, и Я имею Mesh Collider. Все имеют Mesh Collider.
  8. Материалы!!! Побольше материалов !!!
  9. Destroy() в каждой строчке :)
  10. GameObject.Find.FindGameObjectWithTag.FindWithTag.FindObjectsOfType 
  11. Главный персонаж  (2000 полигонов) + Враги ( 2000 * 30 человек)= 62 000 полигонов одновременно !!!
  12. Skybox для 2D игры - лучший выбор (+ 6 drawcall сразу)
  13. Максимум света - прикрепите источник света на каждый лазер, на каждый снаряд !!!