RequiredAttribute

Required is used on any object property, and draws a message in the inspector if the property is missing.

Use this to clearly mark fields as nessessary to the object.

namespace Sirenix.OdinInspector
{
[AttributeUsageAttribute((AttributeTargets)384, AllowMultiple = False, Inherited = True)]
[DontApplyToListElementsAttribute]
public sealed class RequiredAttribute : Attribute
}

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 1.0.5.0

See Also

Constructors

Definition Description
RequiredAttribute() Adds an error box to the inspector, if the property is missing.
RequiredAttribute(InfoMessageType) Adds an info box to the inspector, if the property is missing.
RequiredAttribute(string) Adds an error box to the inspector, if the property is missing.
RequiredAttribute(string, InfoMessageType) Adds an info box to the inspector, if the property is missing.

Properties

Return Type Definition Description
string ErrorMessage The message of the info box.
InfoMessageType MessageType The type of the info box.

Example

The following example shows different uses of the Required attribute.

public class MyComponent : MonoBehaviour
{
	[Required]
	public GameObject MyPrefab;

	[Required(InfoMessageType.Warning)]
	public Texture2D MyTexture;

	[Required("MyMesh is nessessary for this component.")]
	public Mesh MyMesh;

	[Required("MyTransform might be important.", InfoMessageType.Info)]
	public Transform MyTransform;
}