unity 3d game stuttering/ jittering on mobile phones especially ios, even if it is just a simple game… Solution suggestions

it’s been a frustrating few weeks lately, discovering the issue with a mobile game that was built to be super efficient on a mobile platform from unity was extremely difficult, let alone impossible… but there is hope at the end of the tunnel…

for anyone that is facing this problem, i can offer you a solution, it might not be perfect but it will help to considerably improve the performance and reduce the stuttering to a bare minimum, i wish i could say it will be perfect, but it’s not..

1- set the target frame rates to -1: why -1? it  is a special value that tries to get the native frame rate from your device and applies it to your game.

how to set the target frame rates to -1? well its very easy: create a c# script and in the start fucntion: do this:

void Start(){

Application.targetFrameRate = 1;
}

2- if your game relies on physics, any transform changes you apply (for your non physics objects ie: the camera following a physics object) make them in the LateUpdate function and not in Update.

3- Never create new variables in the Update, LateUpdate,FixedUpdate functions, always create your variable at the Start/Awake, or before the Start Fucntion just to avoid some nasty garbage collector behavior.

4-Any Collider (2D or 3D) that is moved by your script using a transform MUST have a rigid body assigned to it and it should be set to kinematic. otherwise make it a trigger if you do not need to assign a rigid body to it.

5- Objects pooling: avoid at any cost to instantiate any object in your scene dynamically, always use object pooling as in instantiating all of your objects in the start function and assign them to an array(preferably) or a list, remember this: lists are easier to use, but are at least 5x slower than unity arrays, so use them wisely.

6-for ios: force OpenGles 2.0 or 3.0 or metal, here you should experiment with each and every one to see which one suits your game better. Go to build settings, player settings, un-tick automatic graphics API and add only the one you want to test so it will be forced.

7- NEVER use FixedUpdate for smooth motion, it will only make your stuttering worst.

8 – try to avoid using Vector3.Lerp, instead try using Mathf.Lerp to lerp a float value and use vector3.set to assign that float value to your vector3, vector math is super expensive.

for example:

vector3 myvector = vector3.zero;

float yvalue = 0.0f;

void Update(){

yvalue = Mathf.Lerp (yvalue, 10.0f, 0.02f);

myvector .Set(myvector.x,yvalue,myvector.z);

}

aslo try to avoid vector3 math, as in multiplying a vector3 is much more expensive than multiplying a single float value of that vector3

9- Shaders: its very important to use the right type of shaders for the right platform, avoid using the standard shader for any mobile platform, try using the unlit or mobile ones instead.

10-go to edit project settings and then choose quality, for the mobile platform:

if you aren’t using any lights, set pixel light count to zero.

if you can get away with lower resolution textures set the texture quality to half res

if your game is a 2D game and you dont have some weird angles, just disable anistrophic textures.

turn off soft particles, real time reflections probes etc.. if your game doesn’t use them.

disable shadows if your game doesn’t use it

set vsync count to every v blank (very important)

11- Multiply by Time.deltatime, every float value that is constantly changing.

12- avoid having multiple shaders for your rigged meshes, it computationally heavy.

13- use the same shader for multiple objects in your scene, if most of your objects share the same shader with the same texture, you will get dynamic batching, it will save you alot of computations.

14- disable realtime GI in case your game doesn’t rely on it, you have to do this for every scene you have from window->lighting

15-dont use the original unity realtime skybox on mobile, instead use a color, or an image based skybox.

16- avoid at all cost using the meshcollier, use very carefully the 2D polygon collider.

hopefully this list could help someone out there and fix your game stuttering/jittering issues on ios and Android

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s