- Home /
Very Bad Performance on Android
Hi! I'm very new to unity and I'm currently finishing up my game. It's a simple slender page collecting game. It runs fine on PC and on my phone (Pocophone f1) but runs very slow on my beta testers devices, their devices vary but most of them are old phones but could still run decent games that are much more detailed than the game I am making. Their phones could run NBA 2k19 just for reference purposes.
I have read multiple posts and watched videos on optimization. Almost all of them recommended the use of the profiler in unity. Here is a screenshot of what I've found so far. After turning down all the details on every texture It still had very minimal impact on performance and I am still very lost here all answers will be appreciated
@L9Zaro Check out my answer. If it helps and solves your issue, accept it as answer. Thanks.
Answer by WaqasHaiderDev · Jun 02, 2020 at 05:37 PM
Hi, elaborate your problem further. Recently I have gone through the same problem and I have learnt unity optimizations from the Unity Online Guides. By use of them I could increase speed of game by 8 times and can reduce size of the game by 50%. But all the speed optimization techniques target 60 frames per second for a good smooth game of android (for VR I have read limits are more i think 90 FPS but for android regular games 30 FPS for RPG and 60 FPS for shooting or racing games is enough. 60 FPS in any case is ideal.)
So your profiling window shows that you are achieving 60 FPS easily so I could not understand your exact problem. But I will guide you the best practices for the SPEED and SPACE Optimizations both. (May be I miss something and they are not perfect but they are best starting guidelines and will gives you direction.)
Use profiling window along with frame debugger to know about draw calls and use Build Report to know about which is taking more size. To know about these tools, if you don't already know, let me know and I will explain.
SPEED OPTIMIZATON :
You have told that you have compressed your textures. This will Impact your Game Size and will not much affect your speed of the game. The most important factor to control in speed optimizations is DRAW CALLS. Basically Draw Calls means GPU and CPU will have to work more if there are more draw calls. CPU sends instructions to GPU and GPU does rendering. So more draw calls is heavy for both. To check draw calls, play game and then click on stats button on top right corner of play mode window to check how many Draw Calls ( BATCHES) are being rendered. Typically 50 to 100 batches are good for android. Any thing beyond 100 will start to impact on android. If you want to learn every deep detail I will give the link of a MUST READ post at end. But you will need to do the following to reduce draw calls.
To to limit Camera frustum and try to include only the limit to render. Use good sky boxes to cheat the player to give player sense of big worlds. -Use camera distance layer culling. For that you can find a script online. Otherwise use this script at attach to your camera. This will cull different layers on distance basis. e.g. if you want to make roads and tree visible for longer distances and for props etc for shorter distance, just enter the required distance upto which you want some layer to be visible.
using System.Collections; using System.Collections.Generic; using UnityEngine; //READ ME // To use this script, size of array of distances must be equal to the number of layers i.e. 32 in unity so size of distances array is always 32. // We can change cullting distance of any array by inserting culling distance to the relevant number of array i(i.e. equal to layer index) public class CullingLayerDistance : MonoBehaviour { [SerializeField] private float[] distances; // Start is called before the first frame update void Start() { Camera camera = GetComponent<Camera>(); camera.layerCullDistances = distances; } // Update is called once per frame void Update() { } }
use ocluision culling. This will increase size of game to 1 to 2 mb may be but it will reduce draw calls and will render only those objects which are in camera frustum and will not render or calculate any object which are behind or outside of camera frustum. (play with settings i.e. smallest occluder size to get occlusion culling size reduce)
Some times props unnecessarily increase draw calls so to reduce draw calls, mark such objects Batching Static. Static objects reduce draw calls a lot upto 50% or even more but it will increase size of the game also. Basically for each batching static object, unity creates a duplicate mesh (I don't know exact details but it is something like this) and unity will load that shared mesh at run time to reduce draw calls and render time but this shared mesh will increase size. So do not include all objects. Only necessary which are problematic.
Use light baking. Real time light is very performance heavy so for static objects use light baking. Also for if similar types of objects will be in different light maps, so those will not be batched together dynamically and will increase draw calls. So to force same objects in same lightmap, create lightmap parameters and assign some similar number to bakedTag and assign these parameters to similar objects. The exact bakedTag number does not matter but it should be same for similar objects and for different objects make new lightmap parameter with new bakedTag and assign that to new objects. Also reduce LIGHTMAP SCALE of each object. I use 0.1 to 0.05 also for some objects if lighting results are not bad. This fits more objects in single light map and allow me to have lesser lightmaps hence less game size. And when changing lightmap scale, I, probuilderize the objects and hit on GENERATE LIGHTMAPS option because it reassigns the UVs as per new scale and then the baked lightening will be smoother. (I am not sure about this but this is how it works for me so I assume this might be the reason behind this)
Also to force same materials in same batch, adjust rending queue numbers. Same concept here. Exact number does not matter but if you will leave all materials at default, then similar objects will not be rendered with sequence. But if you will change render que numbers e.g. for Cars it is 2045, for people it is 2046 for trees it is 3022 etc then all cars will be rendered first and then people and then trees etc but if all will be at default, then Car then tree then car then people than car etc and it will mix every thing and will increase draw calls. Setting this reduce draw calls in dynamic batching. I don't remember but these baked tag and render que may be must for static batching also. (2000+ is for opaque objects, 3000+ is for transparent and so on. You will find its details in render que option)
use mobile shaders instead of standard shaders. Mobile shaders are performant and meant for mobiles. For transperacy use Mobile alpha blend under Mobile > Particles option, for diffuse use Mobile Diffuse etc. -Use objects with lesser materials and avoid objects which use mutiple materials to make same object e.g. to make a person, use object with proper texture map and not a model which use different material for arms, different for shirts, different for pants etc. This will increase draw calls.
Reduce polycount of objects. This will help in dynamic batching. (I use decimate modifier in blender to do so)
Compress textures (I don't remeber how this helps in speed but I noted it down when i studies all this so I added this also)
Improve canvas.build optimization by sprite atlases using sprite packer. To use this Add a component called Sprite Packer. Put all your UI in a folder and assign a folder to this sprite packer and hit Pack. This will reduce size as well as draw calls of UI draw calls.
Also check from profiling window if some physics is involved in reducing speed of the game. In my case, I was using raycasting with some AI vehicles and I accidentally increased ray casting upto 6 times so it reduced speed a lot. I detected from profiling window and corrected issue.
SIZE OPTIMIZATIONS
Reduce textures and make them POT (Power of Two i.e. multiple of 2^2 e.g. 64,128,256, and so on) because this will use crunch compression. Let say your image is not a POT image (means its size is not 64 x 64 or 128 x 128 or 64 x 128 etc) and e.g. it is 64 x 100 then you can make the blank image of POT of 64 x 128 size and then paste your image inside with remaining 28 blank and improt it into unity and now unity will consider it POT and will use crunch compression which reduces size a lot.
Filter and delete unnecessary items from Resource folder. Some times unnecessary Resource folders from different plugins are imported in out build which we are not using at all. So search for any folder with the name Resources throughout your project folders and delete any unnecessary items.
Avoid unnecessary static batching as much as possible and use other rendering optimization techniques as much as you can. Also dynamic batching reduces draw calls without taking space even for static elements.
Add MESH COMPRESSION must if can do. It can reduce size in MBs as well. i.e. for every imported FBX model or mesh, there is an option in Import settings to Compress mesh. Do that if it does not affect quality etc.
you can check which dlls are included in build report. But this is a bit tricky. If you find any unnecessary dll then you can delete that plug in I think. I tried this but could not be succeeded.
-Remember, every speed optimization step has a disadvantage in terms of space allocation mostly. So it is a balance.
MUST VISIT LINKS : Mobile Optimization Practical Guide Unity
@L9Zaro As you said, your game reached 60 FPS at your PC and becomes very slow at friend mobile, this is because your are not analyzing game at your target platform. Do profiling of game always at target platform because then it will gives you true picture. To do this, connect the mobile with you computer. And make a DEVELOPER BUILD. When making a build, click on the options I have shown in image i.e. Development Build and AutoConnect Profiler. Also I have shown my Player Settings so that you can have an idea what I selected to increase my speed. I don't say my settings are flawless or perfect but they are doing good for my current vehicle simulation game. $$anonymous$$ost important are "Rendering" section from the "Other Settings" section. You should focus and study about these settings as well to increase performance of game. There is a section of "Optimization" as well. I don't know all nor I remember but this should give you a direction.
$$anonymous$$ust check on youtube or the documents I have shared how to Use Profiling Window and Frame debugger because they will give you exact picture of the game performance.
PS : I am not able to attach Images. I don't know why. I attach, click upload, it just stuck there forever.
Also I just came to know something about GPU INSTANCING option in material settings. This is very good alternate of static batching. Even it batches objects together which static batching misses in my case. But the problem is that GPU instancing only works with OpenGL ES 3.0+ and as per google distribution, 14% devices are OpenGL 2.0 so I can't use this option ins$$anonymous$$d of static batching. I have seen come free tools on unity asset store which further optimizes the meshes, materials and textures which I will use once my game is completed. $$anonymous$$y draw calls were 800+ initially and then I reduced it to 100. Now it is again ranging from 100 to 200 because I have added features and objects. So I will use every possible aspect to reduce the draw calls once my game is finished in a week or so. I will keep here updated.
Answer by mazen1243 · 2 days ago
you must set reslution low
Screen.SetResolution(640, 480, true);
I know this sounds like sacrilege but modern phones have screen resolutions like gaming PCs. They can't have the power of a PC graphics card (unless you don't mind your phone bursting into flames) and are often fill rate bound.
Halve the horizontal and vertical resolution and you're outputting a quarter as many pixels. This particularly applies if you're using complex shaders or applying post processing.
My game was dog slow on a Note10 until I halved the resolution. Now it's back up near 60fps and I defy anyone to see the difference.
Answer by L9Zaro · Jun 04, 2020 at 12:17 AM
@GameHourStudio Thanks I will notify you after I tried it out! It reaches 60 easily on my pc but when its on my friends phone its painfully slow
I am new to unity answers. But What I have read i other posts, don't post your comments as answers. Try to post this comment below the answer of $$anonymous$$e so that chat seems continuous to other readers. There I am posting answer of this question. Below my answer.