One of the most common errors in any Unity project are the
NullReferenceException,
haunting developers nightmares. This package makes it easier to spot when a serialized fields in the Unity Editor is
left empty, even though they should be set. With this new [Required] attribute, you (as a software developer) can be
sure required fields in the Unity Editor are communicate with your team members, no matter what.
- Open the Package Manager in a Unity project.
- Click on the "+" button to add a new package.
- Click on "Install package from git URL...".
- Put in
https://github.com/Incantium/Required.git. - Click on "Install" or press enter.
- Enjoy!
- It is impossible to reference classes that cannot be referenced through the Unity Editor (that do not inherit from Object or IRequireable).
To make any referenceable field required in Unity, you only have to do the following.
using Incantium.Attributes;
using UnityEngine;
public class ExampleClass : MonoBehaviour
{
[SerializeField]
[Tooltip("The target position of the enemy. Not setting this field will give a warning in the Unity Editor.")]
[Required]
private Transform target;
}| Class | Description |
|---|---|
| IRequireable | Interface for other classes able to be required. |
| Required | The Required attribute to show a warning in the Unity Editor when found to be empty. |
| RequireStatus | The different statuses a required field can be in. |
This package is heavily tested in Unity 2022.3.44f1 and Unity 6000.0.25f1. It is expected that this package also
works in older and newer versions of the Unity Editor because it is not dependent on any other Unity package.
This warning shows up when the field to be required is not referenceable through the Unity Editor (like all primitive data structures such as integers, floats, and booleans). Only the classes inherited from Object are referenceable through the Unity Editor. The exception is the IRequireable interface, which also makes it possible to be required.
Yes. It is possible for classes that don't inherit from Object to be requireable, such as serializable classes. These classes need to implement the IRequireable interface to function properly with the Required attribute.

