Validate Using Attributes

One of the most common ways to use the validator is to add attributes to your classes and class members.

The Odin Validator plugin adds the ability to scan and fix issues across your entire project, but these attributes also work without it.

The currently supported built-in attributes are:

Let's have a look at an example of how a properly validated component might look like.

public class Player : MonoBehaviour
{
    [Required]
    public string Name;
    
    [MinValue(0), MaxValue(100)]
    public int Health;
    
    [ChildGameObjectsOnly]
    public GameObject Child;
}

Using these attributes diligently throughout your project will make sure your project remains stable as it grows and will make it easier to onboard new team members.

The built-in attributes cover a wide range of validation needs, but sometimes you will still have to create custom validators to validate your components. You can learn more about creating custom validators in the following tutorials.

Validator Types

Are you interested in creating custom validators? Check out this overview to see which one is right for your use case.

Validator Types Overview

Validators vs Validation Rules

You already know how to create custom validators and are interested in the difference between Validators and Validation Rules? Then this tutorial is right for you.

Validators vs Validation Rules

Custom Fixes

Validators can have custom fixes that can be executed with the push of a button. Check out this tutorial to learn how to add fixes to your validators.

Creating Custom Fixes