Version 3.3.1.2

Odin has a dedicated attribute overview with examples

RequiredAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Parameter | AttributeTargets.Delegate | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter | AttributeTargets.All, AllowMultiple = false, Inherited = true)]
[Conditional("UNITY_EDITOR")]
public sealed class RequiredAttribute : Attribute, _Attribute

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 necessary to the object.

Inheritance
  • System.Object
  • System.Attribute
  • RequiredAttribute
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;
}

Constructors

RequiredAttribute()
Adds an error box to the inspector, if the property is missing.
public RequiredAttribute()
RequiredAttribute(InfoMessageType)
Adds an info box to the inspector, if the property is missing.
public RequiredAttribute(InfoMessageType messageType)
Parameters
InfoMessageType messageType

The type of info box to draw.

RequiredAttribute(String)
Adds an error box to the inspector, if the property is missing.
public RequiredAttribute(string errorMessage)
Parameters
System.String errorMessage

The message to display in the error box.

RequiredAttribute(String, InfoMessageType)
Adds an info box to the inspector, if the property is missing.
public RequiredAttribute(string errorMessage, InfoMessageType messageType)
Parameters
System.String errorMessage

The message to display in the error box.

InfoMessageType messageType

The type of info box to draw.

Fields

ErrorMessage
The message of the info box.
public string ErrorMessage
MessageType
The type of the info box.
public InfoMessageType MessageType