Skip to content

Latest commit

 

History

History
37 lines (28 loc) · 841 Bytes

File metadata and controls

37 lines (28 loc) · 841 Bytes

UNT0019 Unnecessary indirection call for GameObject.gameObject

Unity GameObject has a property gameObject that returns this. This allows calls like GameObject.gameObject.gameObject to occur which is redundant and hinders performance.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    private void OnTriggerEnter(Collider collider)
    {
        GameObject original = null;
        GameObject duplicate = original.gameObject;
    }
}

Solution

Fix expression:

using UnityEngine;

class Camera : MonoBehaviour
{
    private void OnTriggerEnter(Collider collider)
    {
        GameObject original = null;
        GameObject duplicate = original;
    }
}

A code fix is offered for this diagnostic to automatically apply this change.