06. Attributes No Comments

When added before a collection type class member, indicates that the value of any of its members can not be null.

Any member whose value is null will be highlighted with red color in the inspector view.

Attribute Target

Field, property, indexer, method return value or method parameter.
Target type must be a collection of some sort (e.g. Array or List).


using UnityEngine;
using Sisus.Attributes;

public class MissingScriptDetector : MonoBehaviour
	[NotNullMembers, ReadOnly, ShowInInspector]
	private Component[] components;

	// called when the script is loaded or a value is changed in the inspector
	void OnValidate()
		components = GetComponents<Component>();

		for(int n = 0, count = components.Length; n < count; n++)
			if(components[n] == null)
				Debug.LogWarning("Missing component found on GameObject "+name, gameObject);