With Unity 2019.3, Odin Project Validator 2.1.12 will not stop build when validation error is exist.

Issue #663 resolved
Ryota Murohoshi created an issue

# Environment

Unity 2019.3.12f1
Odin Inspector 2.1.12 (download source code from https://odininspector.com/download)
Odin Validator 2.1.12 (download source code from https://odininspector.com/download) )


# Reproduce

1. Import Odin Inspector 2.1.12 and Odin Validator 2.1.12 with Unity 2019.3.12f1
2. Create next code.

using UnityEngine;
using Sirenix.OdinInspector;

public class ExampleRequire : MonoBehaviour
{
    [Required] public GameObject gameObjectReference;
}

3. Create ExampleRequire component.

4. Create example scene.

5. Create GameObject and add ExampleRequire component it. Do not set reference for gameObjectReference to make fail validator.

6. Add example scene to build settings.

7. Open Validation Config with Tools > Odin Project Validator > Manage Profiles.

8. Open Hooks tab and set enable Open Build checkbox.

9. Click Actions tab, and set enable Stop Hook Event On Error

10. Build Project with platform PC, Mac & Linux Standalone.

With above steps, build will finish and will not stop.

Sorry updated.


# Expect

With above reproduce process, there is a validation error at ExampleRequire ScriptableObject.
So I expect that build process will stop and build will be failure.


# Cause I expect, Fix idea I expect

With Unity 2019.3, build will not stop when Exception is thrown on `OnPreprocessBuild(BuildReport report)`.

At the code on `Assets/Plugins/Sirenix/Odin Validator/Editor/Scripts/Automation/OnBuildValidationHook.cs`, `Exception` is thrown at `OnPreprocessBuild(BuildReport report)`.

// L69-72
public void StopTriggeringEvent()
{
    throw new Exception("'On Build' validation hook throwing exception to stop build process");
}

At the code on `Assets/Plugins/Sirenix/Odin Validator/Editor/Scripts/Automation/OnBuildValidationHook.cs`, how about change from `Exception` to `BuildFailedException`?

// L69-72
public void StopTriggeringEvent()
{
    throw new BuildFailedException("'On Build' validation hook throwing exception to stop build process");
}

With above code, build will stop when there are some validation error asset or scene.
Please check above code and please consider above change.
Please check stop the build process with Odin Validator with any Unity version.

Comments (8)

  1. Tor Esa Vestergaard

    Sometimes, there is no way to stop a build, short of crashing the editor. It seems to vary greatly from version to version of Unity, what it takes to stop a build from happening. Sometimes an exception must be thrown, sometimes an error being logged is enough, and sometimes the build doesn’t care. We’ll check it out in this version of Unity and see if we can figure out what might work there.

  2. Tor Esa Vestergaard

    Though, rereading your message, you seem to have found the way that probably works already, for us - sorry, haven’t had my coffee yet!

  3. Tor Esa Vestergaard

    I’ve implemented the suggested change and it appears to do the job; if you would like a build with the fix included, please contact me on Discord and I’ll send it to you. Though of course, in this case, the change is so simple that you can just change the source yourself for now. Thanks for reporting the issue!

  4. Log in to comment