Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 593 Bytes

UNT0002.md

File metadata and controls

35 lines (26 loc) · 593 Bytes

UNT0002 Inefficient tag comparison

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.