Skip to content

Latest commit

 

History

History
41 lines (30 loc) · 650 Bytes

UNT0007.md

File metadata and controls

41 lines (30 loc) · 650 Bytes

UNT0007 Null coalescing on Unity objects

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

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
	public Transform a;
	public Transform b;

	public Transform NC()
	{
		return a ?? b;
	}
}

Solution

Use null comparison:

using UnityEngine;

class Camera : MonoBehaviour
{
	public Transform a;
	public Transform b;

	public Transform NC()
	{
		return a != null ? a : b;
	}
}

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