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

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

Requirements

Namespace: Sirenix.OdinInspector
Assembly: Sirenix.OdinInspector
Version: 2.0.0.0

See Also

Fields

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

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.

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;
}