Guarding

Learn how the Guard validation framework works in Validatox and how it can deliver useful utilities for your project

Introduction

The Guard validation framework allows to perform validation on references of any script in the project inheriting from UnityEngine.Object.

Guard validation is performed by the GuardValidator. Validatox provides a default GuardValidator that is located in the package Editor folder.

Override default GuardValidator

In order to override the custom GuardValidator, create a new one in the Asset/Editor folder by selecting: Create -> Validatox -> Guard validator

GuardAttribute

The Guard attribute is the marker that allows the GuardValidator to identify and validate the field the attribute is associated to.

When marking a field with the attribute, it is assured that when running the GuardValidator, it will identify the field and check its value, in order to validate its reference status.

[SerializeField, Guard] private GameObject prefab;

The prefab field is marked with the Guard attribute and is serialized in the inspector. When validating, the GuardAttribute will verify that the field is populated.

Note that the GuardAttribute works only with reference type fields.

Last updated