UEA0016: VectorMagnitudeIsSlow
October 6, 2019 ยท View on GitHub
| Property | Value |
|---|---|
| Id | UEA0016 |
| Category | Performance |
| Severity | Info |
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)
{
}
}
}