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

 

 

 

Mesh and objects deformers tips and tricks

preview

How to use the object deformer scripts?

you need to first create an empty Game object, attach to it as children all the objects you want to manipulate, now also attach to it any of the objects deformer scripts: ie : Object image deformer, objects sine deformer, or objects ripple Deformer.

In Version 1.1 (currently pending review) you can do the following:

go to the menu: mesh deformer->create 2D grid or create 3D grid

this will create a grid of objects according to the settings you set in it.

in the hierarchy select the grid handler and apply to it the object deformer script of your choice, either manually or through the menu item: mesh deformer->attach…

How to use a regular deformer?

make sure the object u are using has a mesh mesh filter adn assign to it any of the deformer scripts.

in version 1.1 you can assign the scripts to multiple objects simply by selecting them and going to: mesh deformer->attach…

Version 1.1: How to use the colorize Script:

you attach the colorize script to the parent game object that holds all the children game objects you want to colorize and change its settings to suite your needs.

How to use images for deformation  or coloring (image deformer/ objects image deformer/ and colorize script).

when importing the images, make sure to choose advance and enable read/write.

Version 2.0  Tips:

Skinned Mesh Deformers tips:

-to use the skinned mesh deformer, you need to assign the right script to the Skinned Mesh ie: the Mesh that has a skinned mesh renderer attached to it.

PS: skinned meshes apply to all the instances of the same mesh in the scene, you only need to assign it to a single one of them, if you want to assign different skinned mesh deformers to other instances of the same mesh in the same scene, sadly you need to import a new asset and assign to it the other script. for example you need to import the same character twice into unity.

  • always use the menu to assign the scripts
  • you can use the same effector to all three of the objects deformer script: translate/rotate/scale, by assigning the same effector to the effector object of each script and deleting the ones you don’t need.
  • you can create your own effectors by assigning the effectorval script it to your own game object and assigning the gameobject to the effector value of the object deformer.
  • you can also create an effector by simply using the mesh deformer menu and choosing create effector, but you will have to also manually assign it to the script you need to use

How to stack multiple mesh Deformer?

well, at it’s current state the meshes are not stack-able, but you can stack them indirectly, when in play mode, edit the parameters of the mesh deformer, when you are satisfied you can use this script to export the mesh as an OBJ (use instructions are included in the link). when done import the mesh to your scene and apply a new mesh deformer to it. not the perfect solution, but it’s a way.