UNT0002 Inefficient tag comparison
March 15, 2025 ยท View on GitHub
Comparing tags using == is slower than using the built-in CompareTag method.
Examples of patterns that are flagged by this analyzer
using UnityEngine;
public class Camera : MonoBehaviour
{
private void Update()
{
Debug.Log(tag == "tag1");
}
}
Solution
Use CompareTag method:
using UnityEngine;
public class Camera : MonoBehaviour
{
private void Update()
{
Debug.Log(CompareTag("tag1"));
}
}
A code fix is offered for this diagnostic to automatically apply this change.