Version 2.1.0.0

Odin has a dedicated attribute overview with examples

RequiredAttribute class

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector.Attributes
[DontApplyToListElements]
[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)]
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

This website is brand new and built with the Odin 2.1 beta in mind. This means you might discover some features such as attribute expressions that are only available in the beta.

You can download the 2.1 beta from here and read the patch-notes here.