Unity mobile game lag + profiler herlp

Viewed 4692

I am working on a simple game for mobile. Im a beginner/intermediate. My game is a simple endless runner like crazy taxi where you are jumping over other cars. For the environment I used a low polly free asset pack. The game runs perfectly on my laptop but when I built an apk and checked on a couple of devices its lagging a lot.

This is what the game looks like.

I used low poly assets so I thought it would not be an issue. I understand that mobiles have much less resources so how can I fix this problem or avoid it in the future? I see many top games on the app store with so much going on and many particle effects etc as well as many unity games so how do those people do that?

Attempt at resolution:

I have done a lot of research but I dont really understand. I read up on something about mobile shaders. So I thought I will change my shaders on the assets to mobile/diffuse from the standard but when i do that many assets lose their entire texture/color and become white.

The second thing I tried was the texture compression option on the build screen. There are options like DXT, ETC, ETC2, PVRTC, etc I tried all of them one by one but that did not seem to make a lot of difference.

Lastly I decided to have a look at the profiler. This is my first time using the profile. There really isnt much material online for beginners regarding such questions. In the profiler I notice that the most cpu use is because of Camera.Render and it usually takes average time 9ms. The rest of the things usually take substantially lower time with most taking times like ~0.1. I dont know what 9ms means or if its a lot. I just have a simple camera script moving the camera behind the player.

Profiler s/s

I tried simplifying the environment and that caused the value to drop a bit, like ~7ms but I made the scene very simple and I dont want that I want to make a beautiful environment.

One last thing, At the moment since its an endless runner I have 5 prefabs for my roads and I am deleting and instantiating them. I know that is not good practice and instead I should just use a pool, but can this be the reason for the lag? The reason I havent done object pooling yet is that at the very beginning I would have to generate like 50 prefabs in my pool ten of each kind and thats just for 5 prefabs ideally I would like to have a wide variety of prefabs for my roads so the environment doesnt look repetitive. if anyone can help I would be forever indebted.

/e I have since set the settings to very low I have stopped auto generate lighting and also disabled shadows.

This is a s/s of my stats.

s/s with simple cubes...

This is starting to become increasingly hopeless. I dont see how theres any way I can get close to <50 batch count. The screen shot above uses simple 3d cube objects and that still gives me a batch count of 20-30. The minute I add some assets to make the scene prettier it goes up and starts lagging on my mobile.

2 Answers

Drawcalls and shadows. I will give you better and bigger answer in a few hours because I'm currently working but read about drawcalls and in Edit-> Project Settings - > Quality - >Android set everything on low and disable shadows. Mobile devices are not good in rendering dynamic lights and shadows. Also - you should use pool system because with big prefabs it can really slow the game and make it freeze on prefab spawn. On low end-mid end devices drawcalls(currently called batches in unity) can be a huge bottleneck. Press stats in your unity3d game window and see how many batches do you have. For mobile it should be around 10 to 30 at max, at least in my experience.

these low poly assets actually are not so low poly for mobile and they have many different materials and consist of many child objects. Also if you use terrain change it to plane. And the heaviest thing is dynamic lightning and shadows.

Related