Android Laggy Sometimes
Hello there! I have a little problem. I making a runner-like game, where there is a lot of obstacles and they are moving on player. Sometimes, there is a little bit of freeze: obstacles seems moving rougly on a one frame per ~0.3 second;
Im trying a lot of things, to remove that, but unhappy. In the profiler, there is performance pick on Camera.Render.TransparentGeometry and nothing more. Im using Toolkit2d, compression ETC. Moving the obstacles by modify localPosition Also have noticed, when logging android deltaTime, that sometimes it huge different from usual (usual deltaTime 0.016, and sometimes its goes to ~0.02, 0.03)
I have no idea what I can check and update to make gameplay idealy smoothed. Can you help me with some ideas?
Edit: I have checked some other devices. This lags only on my device, and a little bit of this lags on some other. The most devices have no lags Why it can be? My main test device is OnePlusOne, should be a very good and with no lags...
Answer by fishbrainz · Apr 11, 2016 at 01:41 PM
Check to see if you have a rigidbody2d on your moving gameobjects that have a collider of any kind. Gameobjects that only have a collider on them with no rigidbody are considered Static Colliders and thus should never be moved infoLink.
Also when moving an object with a rigidbody attached either use its velocity property to move it, or if you still want to move it via its transform try transform.Translate(), and compare performance results.
Another lag source for your problem could be the instantiation of objects. Unity's OnEnable() methods are pretty costly when run the first time on an instantiated object, it requiring to draw the graphic, and initializing any other components attached. So most initializations should be done on game launch when you have a bunch of down time to work with.
Are you using any object pooling solution? If no i would highly recommend you look it up and try it. A good pooling solution i found for unity is PoolBoss. A great number of Instantiations could create more objects in your scene than your GPU can handle to draw at once, and so creating a lag spike.
Thanks you for your answer! I will check you checklist and give some response later here ;) All my moving object have BoxCollider and no rigidbody Im using my own pool-solution. I comparing with PoolBoss on my project and they are equal on performance
Some questions: Later im tried to make colliders Statiс (so its seems bad solutions, they should not be moved) and im tried to give them all rigidbody (I forget the result, and i will make it again) it is require a lot of CPU, isnt? I mean for rigidbody for every objects with colliders