Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 599 Bytes

UNT0008.md

File metadata and controls

35 lines (26 loc) · 599 Bytes

UNT0008 Null propagation on Unity objects

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

Examples of patterns that are flagged by this analyzer

using UnityEngine;

class Camera : MonoBehaviour
{
	public Transform NP()
	{
		return transform?.transform;
	}
}

Solution

Use null comparison:

using UnityEngine;

class Camera : MonoBehaviour
{
	public Transform NP()
	{
		return transform != null ? transform : null;
	}
}

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