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

 

 

 

Duplicator

DupSocial

Get it from the assets store here

Duplicator Instructions pdf

Duplicator is a set of duplication tools for unity 3d, that you could easily use inside the editor.
-you can generate brick walls with your own brick 3d model using the generate wall

-you can duplicate (multiple objects) on a surface using the mesh image duplicator tool

-you can randomize your 3d objects using the Randomizer tool

– you can create 3D grids with separation using Create 3D grid tool

– you can create 2D grids with separation with Create 2D grid tool

– you can duplicate multiple objects with different parameters using the duplicate special tool

-you can duplicate (multiple objects) on a flat grid using the image duplicator tool

-you can reduce the amount of objects you have using the Reduce tool either by hiding or destroying the objects

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.

 

Count up timer for unity3d in minutes,seconds and milliseconds c#

I have been asked about how to make a count up timer in unity so many times, that i finally decided to share a simple script that does that, so here it goes.

this script will also format the timer to “00:00:00”

create a C# script in unity and add the following code to it:

float minutes = 0f;
float seconds = 0f;
float milliseconds = 0f;
string minutesS =””;
string secondsS = “”;
string millisecondsS = “”;

void Update(){

if(milliseconds >= 100){
if(seconds >= 59){
minutes++;
seconds = 0;
}
else if(seconds < 59){
seconds++;
}
milliseconds= 0;
}
milliseconds+= Time.deltaTime * 100;
if (minutes < 10) {
minutesS = “0” + minutes;
}
else {
minutesS = “” + minutes;
}

if (seconds < 10) {
secondsS = “0” + seconds;
}
else {
secondsS = “” + seconds;
}

if ((int)milliseconds < 10) {
millisecondsS = “0” + (int)milliseconds;
}
else {
millisecondsS = “” + (int)milliseconds;
}

Debug.Log(string.Format(“{0}:{1}:{2}”, minutesS, secondsS, millisecondsS));
}

Quad or Objects grid creation for unity 3D tutorial C#

Difficulty Beginner

Objectives:

  • Create a grid of quad objects in unity 3D
  • modify the grid’s columns and rows count
  • modify the separation between each grid unit in two axis
  • modify the script to be able to use prefabs instead of just quads

Tutorial:

Lets Start Off by creating a C# script: right click in the project window and choose Create->C# Script just like in the image Below

createscript

now lets rename the script: GridScript

Double click the script to open it in monodevelop or your assigned IDE we get something like the script below.

gridscriptempty

now lets start by creating our variables:

Above void Start write the following:

public int NumberOfColumns = 10; // number of columns for the grid
public int NumberOfRows = 10; // number of rows for the grid
public float SeperationValueX = 0.0f; // Distance between each column
public float SeperationValueZ = 0.0f; // Distance between each Row

private float tempSepX = 0; // used to calculate the separation between each column
private float tempSepZ = 0;// used to calculate the separation between each row

Continue reading

Mesh and Object Deformers for Unity3D

watch a preview on youtube

you can get it from the unity assets store here

deformersThis is a set of deformers, created for unity3D and published on the assets store

its a set of mesh deformers:

  1. image deformer: use a black and white image as a deformer, suitable for terrains and other creative ideas, you can use an image sequence and let it deform the mesh too
  2. sine deformer: deform an object using a sine wave, it can be further adjusted with a curve
  3. Ripple deformer: deform objects with a ripple wave
  4. twist deformer: Twist objects, you can further refine with a curve.
  5. flare deformer: use it to flare up items, and use the curve to modify the flare
  6. curve shape deformer: deform meshes according to the curve in the inspector

and a set of object deformers:

  1. image object deformer: use images to manipulate the position of objects in 3d space, you can also benefit from using a sequence of images to create some cool effects.objectsimage
  2. object ripple deformer: use it to cause a ripple wave on the objectsobjectsripple
  3. object sine deformer: use it to cause the elements to move according to a sine wave, you can also modify with a curve.objectssine