Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 679 Bytes

File metadata and controls

39 lines (28 loc) · 679 Bytes

UNT0029 Pattern matching with null on Unity objects

Unity overrides the null comparison operator for Unity objects, which is incompatible with pattern matching with null.

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
    public Transform a = null;

    public void Update()
    {
        if (a is not null) { }
    }
}

Solution

Use null comparison:

using UnityEngine;

class Camera : MonoBehaviour
{
    public Transform a = null;

    public void Update()
    {
        if (a != null) { }
    }
}

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