Search Unity

Discussion Unity 5 to Unity 2024 android performance tips

Discussion in 'Android' started by UnityLighting, Oct 23, 2016.

  1. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Hello to unity mobile game developers

    I have worked on mobile games about 2 years. These are my performance experiences on unity 5 and mobile devices:
    My main target is Lenovo A3300 with mali400 GPU

    Download all in one documentation

    1. You can change unity height map resolution to reduce terrain triangles(note: after changing height map resolution, your created height map will be lose)
    1.jpg


    2. Unity default sky box uses IBL lighting shader. you need avoid unity default skybox for mobile devices. Its drop around 20 fps on mobile devices. Replace default sky box with new one and change Ambient Source to Color.
    2.jpg


    3.One of the easier ways to achieve high frame rates is that reduce screen resolution: My best choice for low end devices is 800x450(16:9) or 900x506 (16:9)
    3 (1).jpg


    4.Fastest shader for mobiles is Mobile->Vertex Lit shader that reduce draw calls and calculate lighting on Vertex's instead of Pixels.

    5. For particles you can easily reduce max particle counts and set particle size to larger value for same results
    6.jpg

    6. You can optimize scripts with this function
    7 (1).jpg

    7. Occlusion culling is not suitable for mobiles. you can use this best solution for mobile devices without problem:
    https://www.assetstore.unity3d.com/en/#!/content/35100
     
    Last edited: Mar 30, 2021
  2. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    8.Child all static game objects to an empty game object (called "Scene")and set its as static for static batching and reduce draw calls
    Unity Manual Link

    8.jpg


    9.Best performance and good quality settings for low end android devices
    10.jpg
    Best performance and good quality settings for mid-high end android devices
    100.jpg
     

    Attached Files:

    • 77.jpg
      77.jpg
      File size:
      102 KB
      Views:
      4,465
    Last edited: May 13, 2017
    Karmate and Player7 like this.
  3. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    10. Set your terrain shader to Legacy Diffuse in terrain settings
     
    Last edited: Oct 23, 2016
  4. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
  5. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    No. OC is not good for mobile at all. It makes a lot of lags on Low-End mobiles.
    I suggested that you can use Per-Layer Camera Clipping Instead of OC. I've tested it already. It is the best solution for culling on mobiles. You don't need to cull terrain along with other game objects. Its also reduce draw calls.
    My test on the big scene:


    Untitled (1).jpg
     
    laurentlavigne, pokruchin and o1o101 like this.
  6. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    11. Some devices like Xperia Z1 has good GPU chip. but when you play some games like asphalt 8, these games run slowly. Its because Z1 native resolution is 1080p and 1080p is very heavy even for PS4. You can set your default resolution to 720p and run your game with solid 60 fps even with a lots of effects and heavy shaders.

    Not much difference between 1080 and 720 on 6 inch screen.
     
    JamesArndt likes this.
  7. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    How do you do custom resolutions, for example half res, on every different screen size?

    Thanks!
     
  8. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    You can read this in first post
    it is simple:


    These is 16:9 resolutions list:
    1980x1920
    1600x900
    1280x720
    900x506
    800x450
    700x394
    640x360

    Reducing resolution is the best solution to run games smoothly on every devices. you can run a game with 3 images effects with 640x360 res on low end devices.
    I'm added resolution setting to my games settings menu for support to every devices. Players can turn on image effects and reduce resolution or vice versa

    You need add this codes to your main camera on the scene. I set main menu resolution to 1280x720 and game scene resolution according to selected on settings menu.
    You can see Xbox one is 50% less powerful than ps4, but with lower resolution it can run games smoother than ps4!!!
     
    Last edited: Oct 25, 2016
    EvilGremlin and developersice like this.
  9. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hi aliyeredon2
    thanks for the tip they re really usefull, especially for low end mobile, i tryed Per-Layer Camera Clipping it kind of work
    but for some reason all the mesh that has collision mesh component lose their collision . any idea how to fix that?
    cheers
     
  10. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    ah nevermind i find my problem, when creating a new layer i had to enable physic in the physic manager.
    cheers
     
    Taloose and UnityLighting like this.
  11. JamesArndt

    JamesArndt

    Joined:
    Dec 1, 2009
    Posts:
    2,932
    I've found the old M2H Culling free script package works well for mobile platforms. It also works in Unity 5 as well as the 4.xx series. I've used it on several mobile client projects and it's always helped.

    https://www.assetstore.unity3d.com/en/#!/content/221

     
  12. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    12. You can simply bake normal map and occlusion map into diffuse texture with photo shop. Its similar to shader code in runtime(multiply occlusion texture to diffuse texture)
    Watch tutorial
    Download free rocks:Link

    Compare result:
    www.GIFCreator.me_pI53nV.gif
    www.GIFCreator.me_EPxe9e.gif
     
    Last edited: Oct 26, 2016
  13. Durins-Bane

    Durins-Bane

    Joined:
    Sep 21, 2012
    Posts:
    175

    Heres a great video that helped me a lot!

    Especially when you import your models disable the Read/Write toggle
    Also when theyre not needed set normals & tangents to none

    I gained about 15-20 fps just from this

    objects.png
     
  14. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I should test it
    Thank you
     
  15. Durins-Bane

    Durins-Bane

    Joined:
    Sep 21, 2012
    Posts:
    175
    No problem :) let me know if it works, I went from a pretty unplayable game on low end devices (I am using Xperia E3 for testing) to smooth game play. Was really happy!
     
  16. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I've tested it.Nothing has changed. I've tested on Unity 4&5.
    tested on LenovoA 3500 with Mali400 gpu...
     
    Felicityinc likes this.
  17. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    13. Terrain optimization
    13.jpg


    New test with Per-Layer Camera Clipping
    ccl.jpg
     
  18. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Nice tips! shall use these in my projects. :)
     
  19. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I love 60 fps games
    My last game tests:

    Lenovo A3500 - Mali400 MP2
    Resolution : 900*506
    Terrain pixel error = 200
    Per-Layer camera clipping used for everythings
    AmplifyColor
    fps : 40-50

    1.jpg


    Xperia Z1 - Adreno 330

    Resolution : 1280x720
    Terrain pixel error = 200
    Per-Layer camera clipping used for everything
    AmplifyColor + Unity sun shaft
    60 fps with 4 enemies

    2.JPG
     
    JamesArndt and elias_t like this.
  20. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    In this site you can find mobile gpus power and compare to consoles and each others
    http://kyokojap.myweb.hinet.net/gpu_gflops/


    For example my Mali 400 MP2 has 9 GFlops and my Xperia has 120 GFlops power.
    Xbox 20
    X360 240
    Xbox One 1311
    Xbox One S 1405
     
  21. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Looking good, what are the batches/verts in the screenshots you posted above?
    Game looks great by the way.
     
  22. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Without Per-Layer camera clipping:
    batches : 181
    verts : 93k

    With Per-Layer camera clipping:

    batches: 93
    verts : 55k
     
    JamesArndt likes this.
  23. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    My new test with Kino Bloom effect. Its really AAA bloom effect and works very good on mobiles.
    https://github.com/keijiro/KinoBloom

    Typically image effects eat half of the frame rate.

    My test on Lenovo A3500 with mali400 mp2 GPU
    720p : game is run smooth without bloom and has very lag when bloom is on
    900*506 : game is run smooth with bloom effect (30fps)
    1.jpg
    2.jpg
     
    Last edited: Jan 16, 2017
  24. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    @aliyeredon2 Quick question, I noticed in your quality settings you said the anstropic textures set to forced on?
    I thought that it was faster to have it off, what is the reason for this?
     
  25. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    It's just for better texture quality. Especially on road textures.
     
    Last edited: Nov 22, 2016
  26. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Hey, @aliyeredon2 just for you, and anyone else who is wondering, I would not set anisotropic to "forced on"... on my S3, it looses around 20 FPS, instead of you want clear textures, you can set it to "per texture" and then you can bump up the aniso levels on import settings.
     
    UnityLighting likes this.
  27. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    My new test: (Fully light mapped + Light Probes)
    5.3.4 (fps is same):
    Screenshot_2016-11-27-22-09-30.jpg
    Screenshot_2016-11-27-22-11-20.jpg
    Screenshot_2016-11-27-22-13-26.jpg
     
    Last edited: Jan 16, 2017
  28. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Screenshot_2016-11-27-22-34-06.jpg
    Screenshot_2016-11-27-22-36-26.jpg
    Screenshot_2016-11-27-22-41-50.jpg
    Screenshot_2016-11-27-22-49-41.jpg
     
    Last edited: Jan 16, 2017
    EvilGremlin likes this.
  29. o1o101

    o1o101

    Joined:
    Jan 19, 2014
    Posts:
    639
    Interesting, I am sure different devices handle aniso differently, so just be careful with having it forced on!
     
  30. obses

    obses

    Joined:
    Jan 23, 2016
    Posts:
    7
    aliyeredon2, Are you always downscaling resolution to certain value? Or do you use some script and downscale different depending on max screen resolution of device?

    I've tested my game on galaxy note 2(max 720 x 1280 pixels) down to 600 x1065 and it look very sharp, but when I took blackberry priv (max 1440 x 2560 pixels) down to 600 x1065 gives me some pixels.
     
  31. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    First download and test my demo apk:
    http://89.163.206.23/Truck_Demo.zip

    I always add resolution options to my settings menu:
    5c12a2c6-dd31-4752-9982-0592a85f8461_scaled.jpg
     
  32. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    In unity 5 we need to reload the scene after changing resolution.
    This is my code to reload the scene:
    Code (CSharp):
    1.             if (PlayerPrefs.GetInt ("Resolution") == 506)
    2.                 Screen.SetResolution (900, 506, true);
    3.             if (PlayerPrefs.GetInt ("Resolution") == 720)
    4.                 Screen.SetResolution (1280, 720, true);
    5.             if (PlayerPrefs.GetInt ("Resolution") == 1080)
    6.                 Screen.SetResolution (1920, 1080, true);
    7.      
    8.  
    9.         Camera.main.aspect  = 16f/9f;
    10.  
    11.  
    12.  
    13.         if(PlayerPrefs.GetInt("Loaded")!=3)
    14.         {
    15.             SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    16.             PlayerPrefs.SetInt("Loaded",3);
    17.         }
    18.         else
    19.             PlayerPrefs.SetInt("Loaded",7);
     
    EvilGremlin, khaled24 and JamesArndt like this.
  33. AgusB

    AgusB

    Joined:
    Jun 20, 2013
    Posts:
    65
    Excellent tips! Many of them where unknown to me. Specially the skybox.

    What happens if you force an aspect ratio different than the phone screen? Many tablets aren't 16:9 and some phones aren't too. Do they get black borders? Do they render in 16:9 but stretch it to their screen? Having fixed ratio is good for the UI too.

    Also another question, is there anyway of getting some info about the GPU to automatically set the quality and resolution settings when the game first starts?
     
  34. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I've used 16:9 for common screen sizes. You need to add screen ratio option to game settings menu similar to other AAA games.
    You can use this class to find GPU name and set the game settings to your needs
    https://docs.unity3d.com/ScriptReference/SystemInfo.html
    https://docs.unity3d.com/ScriptReference/SystemInfo-graphicsDeviceName.html
     
    Last edited: Jan 17, 2017
  35. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Would be nice to see profiler screenshots of the before and after along with ms timing changes over fps. Also thanks for the tips.

    Managed to get rendering times down to under 4ms with over 100k tri's on screen. ( shaders haven't all been optimised yet )

    I normally focus on optimising code which I have at 1.7ms and let the graphics guys go a bit crazy with the effects.
    Running on a Samsung Galaxy s5
     
  36. murkantilism

    murkantilism

    Joined:
    Apr 30, 2012
    Posts:
    21
    Isn't this bad for objects that are actually dynamic? Doesn't it impact performance if a truly dynamic object is marked static?
     
  37. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    No, only static game objects. If you set an dynamic game object to static, it's cannot move.
     
  38. murkantilism

    murkantilism

    Joined:
    Apr 30, 2012
    Posts:
    21
    Marking a gameObject as Static, for batching, will have zero effect on the physics of the object. You can absolutely move it. If you move such an object the combined mesh itself will not move, however you can do all sorts of things to get around this.

    For example:
    - Moving a root object will correctly move its static children
    - Using the batching utility to recombine meshes (expensive) after moving static objects
    - Instantiating a dynamic object at runtime then when it's done moving, making it static with the utility

    I would suggest re-wording or removing #8. Moving every object in the Scene underneath an empty GameObject and marking everything Static doesn't seem like a good setup. One should mark actual static objects as static and leave the rest alone, or deal with them at runtime as needed.
     
  39. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    8.Child all static game objects to an empty game object (called "Scene")and set its as static for static batching and reduce draw calls

    Making all statics as child of the scene game object, just makes your hierarchy cleaner. You can place each static game objects anywhere in your hierarchy.

    I have read this in unity manual and I've tested . It's work correctly and increase my frame rate. (I read it in unity 4 manual)

    Unity Manual Link
     
  40. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I found a way to detect and set screen aspect ratio based on native screen resolution:
    This should work on all devices
    Code (CSharp):
    1.     void Start ()
    2.     {
    3.  
    4.         float xx = Screen.width;
    5.         float yy = Screen.height;
    6.  
    7.         Screen.SetResolution (1280, 720, true);
    8.         Camera.main.aspect = xx / yy;
    9.  
    10. }
    And another way :
    Code (CSharp):
    1.     void Start ()
    2.     {
    3.  
    4.         // Read and save native screen resolution in game first scene
    5.         if (PlayerPrefs.GetFloat ("NativeWidth") == 0  || PlayerPrefs.GetFloat ("NativeHeight") == 0) {
    6.             PlayerPrefs.SetFloat ("NativeWidth", Screen.width);
    7.             PlayerPrefs.SetFloat ("NativeHeight", Screen.height);
    8.         }
    9.  
    10.         // Set your favourit resolution
    11.         Screen.SetResolution (1280, 720, true);
    12.  
    13.         // Set the camera aspect ratio based on native resolution
    14.         Camera.main.aspect = PlayerPrefs.GetFloat ("NativeWidth") / PlayerPrefs.GetFloat ("NativeHeight");
    15.  
    16.  
     
    Last edited: Feb 18, 2017
    EvilGremlin, LunguM and JamesArndt like this.
  41. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Nice. Any graphics programmer would know this. :)
    Additionally, not exactly android-related, but if you need to set a 1:1 ratio (for example, shadow-mapping camera) then just setting Camera.aspect to 1 is all you need to do.

    A pseudo-widescreen for 4:3 content can be done with this as well, if setting a 4:3 res results in faster performance on your device. (Nintendo Wii games did this for it's 16:9 setting)

    EDIT: Turns out the first code sample does the latter point I mentioned in reverse.
     
    UnityLighting likes this.
  42. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Standard shader behavior is different between ES 2.0 and ES 3.1 api mode in player settings:

    e2.jpg
    e3.jpg
     
    Last edited: Jul 14, 2017
  43. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    Interesting. Although the reflection being better distorted on GLES3 makes sense.
    Is that shot using a cubemap or an actual realtime mirror?

    EDIT: Also, if one looks closely, the car reflections have better filtering on GLES3, probably due to being able to use texCUBElod on GLES3 vs GLES2 texCUBEbias
     
  44. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    1. used baked reflection probes on Standard shader

    2. In ES3 mode, reflections quality are same as pc version on all standard shaders . I didn't tested legacy cubemnap shader quality. But i already had read about better cubemap quality in ES3 features.
     
  45. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    I forgotten tell this that when using ES2.0 api,reflections still good on ES2 device. But when you are using API ES2 on ES3 device, reflections are corrupted!!!
    So just switch to Automatic API Level mode in player settings
     
  46. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    If you believe some things are wrong or bugged, please file a report.
     
  47. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    no it's not a bug.The problem is reasonable
     
  48. FuzzyQuills

    FuzzyQuills

    Joined:
    Jun 8, 2013
    Posts:
    2,871
    True. ES3's actually pretty good, only problem is some phones don't play nice with GLES3. (Like mine for a long time until the bug with GLES3 and Samsung handsets was fixed a while back)
     
  49. Karmate

    Karmate

    Joined:
    Aug 30, 2014
    Posts:
    45
    What about "Player Settings" and "Quality Settings". Any tips for theese?
     
  50. UnityLighting

    UnityLighting

    Joined:
    Mar 31, 2015
    Posts:
    3,874
    Player settings are good by default.
    for Quality settings refer to post #2
     
    Karmate likes this.