Hide
Required

Reminding a given reference type field to be required.

This will check if the field value is a truly value, which means:

  1. ValuedType like struct will always be truly because struct is not nullable and Unity will fill a default value for it no matter what
  2. It works on reference type and will NOT skip Unity's life-cycle null check
  3. You may not want to use it on int, float (because only 0 is not truly) or bool, but it's still allowed if you insist

If you have addressable installed, using Required on addressable's AssetReference will check if the target asset is valid

If you have RequiredIf, Required will work as a config privider instead. See RequiredIf section for more information.

Parameters:

  • string errorMessage = null Error message. Default is {label} is required
  • EMessageType messageType = EMessageType.Error Custom message type.
  • Allow Multiple: No
using SaintsField; [Required("Add this please!")] public Sprite _spriteImage; // works for the property field [field: SerializeField, Required] public GameObject Go { get; private set; } [Required] public UnityEngine.Object _object; [SerializeField, Required] private float _wontWork; [Serializable] public struct MyStruct { public int theInt; } [Required] public MyStruct myStruct;

image

[Required(messageType: EMessageType.Info)] public GameObject empty2;

Image