Optimizing Script Performance
Manual     Reference     Scripting   
Unity Manual > Getting Started with iOS Development > Optimizing Performance in iOS. > Optimizing Script Performance

Optimizing Script Performance

This page gives some general hints for how to improve script performance on iOS.

Reduce Fixed Delta Time

Use a fixed delta time of 15-25 fps. You can change this in Edit->Project Settings->Time. This reduces how often FixedUpdate is called and how often the physics engine has to perform collision detection and rigidbody updates. If you are using rigidbodies for the main character, you can enable interpolation in the Rigidbody Component to smooth out low fixed delta time steps.

Reduce GetComponent Calls

Using GetComponent or BuiltIn component accessors can have a noticeable overhead. You can reduce it by caching a direct reference to the component.

For example:

function Update () {
    transform.Translate(0, 1, 0);
}

You can optimize your script to this instead:

myTransform : Transform;
function Awake () {
   myTransform = transform;
}
function Update () {
    myTransform.Translate(0, 1, 0);
}

Avoid Allocating Memory

Reduce the GUI

function Awake () {
    useGUILayout = false;
}

Use iOS Script Call Optimization

Most of the functions in UnityEngine namespace are implemented in C/C++. Calling such functions from scripts has additional performance overhead. Consider using iOS Script Call optimization in Edit->Project Settings->Player to gain several extra milliseconds per frame:

Optimizing Garbage Collection

Page last updated: 2010-09-24