UEA0016: VectorMagnitudeIsSlow

October 6, 2019 ยท View on GitHub

PropertyValue
IdUEA0016
CategoryPerformance
SeverityInfo

Example

Code with Diagnostic

using UnityEngine;

class C : MonoBehaviour
{
    public Transform other;
    private float farDistance = 5.0f;

    void Update()
    {
        if ((other.position - transform.position).magnitude > farDistance) 
        { 
             //OPTIMIZE THIS CALL BY USING sqrMagnitude
        }
    }
}

Code with Fix

using UnityEngine;

class C : MonoBehaviour
{
    public Transform other;
    private float farDistance = 5.0f;

    void Update()
    {
        if ((other.position - transform.position).sqrMagnitude > farDistance * farDistance) 
        { 

        }
    }
}