The IVerify Interface

The IVerify interface allows you to quickly and easily add checks to your own classes. That way you can run your own checks for that class, for example to make sure that all the variables are set up correctly on any GameObject that has your class added as a component, or perform larger consistency checks like making sure a UI-based script is only used on children of a Canvas-object etc.

How it works

The IVerify interface is actually implemented using the VerifyCheckBase class like any other check you can implement yourself. The Verify Interface check scans if a GameObject or ScriptableObject has a component attached that implements the IVerify class and, if so, calls the Verify(CheckVerifyInterface checker) function on that component.

Since the Verify-function is not called at runtime, this code should not have any impact on the performance of your builds. Still, we recommend surrounding your code with compiler conditionals to exclude the verification logic from your builds:

public void Verify(CheckVerifyInterface checker)
{
#if UNITY_EDITOR
        checker.Check(m_Value > 10, "Value must be larger than 10!", this);
#endif
}

How to use it

On any given class of yours, simply implement the IVerify interface and its one method called Verify() to add your class to the Verification System. From now on, all logic in the Verify()-method will be called when a scan is executed.

using Sparrow.Verification;
using UnityEngine;

public class ReminderTestScript : MonoBehaviour, IVerify
{
    [SerializeField] private int m_Value = 3;

    public void Verify(CheckVerifyInterface checker)
    {
        checker.Check(m_Value > 10, "Value must be larger than 10!", this);
    }
}

See the Creating your own checks page for more info on the checker.Check() method, as well as alternatives and options on how to customize your check results further.

Was this page helpful?