unity3d Optimization Avoid calling methods using strings


Example

Avoid calling methods using strings that can accept methods. This approach will make use of reflection that can slow down your game especially when used in the update function.

Examples:

    //Avoid StartCoroutine with method name
    this.StartCoroutine("SampleCoroutine");

    //Instead use the method directly
    this.StartCoroutine(this.SampleCoroutine());

    //Avoid send message
    var enemy = GameObject.Find("enemy");
    enemy.SendMessage("Die");

    //Instead make direct call
    var enemy = GameObject.Find("enemy") as Enemy;
    enemy.Die();