• Stars
    star
    152
  • Rank 243,527 (Top 5 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Tool for validating objects (eg. GameObjects, ScriptableObjects, etc) in the Unity Editor.

DTValidator

Tool for validating (ensuring no broken / missing outlets) objects like GameObjects, ScriptableObjects, etc, in the Unity Editor.

Why use DTValidator?

It's so easy to break outlets by renaming functions, removing assets, losing .meta files, etc. DTValidator finds missing outlets (any UnityEngine.Object exposed in the inspector), broken UnityEvents, and missing MonoBehaviour scripts.

More importantly, it's easy to set it up as a unit test for integration with your build pipeline.

Read more about DTValidator here.

To Install & Use:

  1. Download the DTValidator project from this repository by pressing this link. It should automatically download the latest state of the master branch.
  2. Place the downloaded folder in your project. I recommend placing it in the Assets/Plugins directory so it doesn’t add to your compile time

Now you have unit tests running to validate your project! Try running them by opening the Test Runner window under Window->Test Runner. It's likely that you'll have errors in your project - that's okay! Most likely the errors will be outlets that you need to mark [DTValidator.Optional]. See the FAQ for the best approach to deal with these errors.

To find and fix these errors, open the DTValidator Window under Window->DTValidator Window.

DTValidator Window Menu Item

Now press the Validate button and all the errors will show up. You can see where the error originated from and even highlight the object in the editor. Go through each error and determine if it’s an actual error or if it needs to be marked [DTValidator.Optional].

Image of Errors in DTValidator Window

Once you’re left with no errors, you’re done! Now set your build system to run unit tests for every build. You can now easily find and check new validation errors when they come up.

FAQ

Q: I have an outlet marked as an error, but it's fine that the outlet is missing. How do I fix this?

A: Mark the outlet as [DTValidator.Optional] and the validator will ignore checking the field.

public class ExampleMonoBehaviour : MonoBehaviour {
	[DTValidator.Optional]
	public GameObject OptionalOutlet;

	[SerializeField, DTValidator.Optional]
	private GameObject optionalOutlet_;
}

Q: There are a ton of optional outlets for this plugin I downloaded, is there an easier way to deal with these errors?

A: Yup! Mark the entire plugin namespace as optional by creating a ValidatorIgnoredNamespace. Right-click in your project and go to Create->DTValidator->ValidatorIgnoredNamespace.

Create a ValidatorIgnoredNamespace

Q (advanced): There's an outlet that is usually required, but in certain conditions it's optional.. can we handle that case?

A: Yep, though it'll take a bit of code. You can add define a function that determines whether the type / field combination should be validated. Here's an example:

using DTValidator;

// This attribute lets Unity know to call the static constructor
// when the Editor starts up, therefore injecting the predicate DontValidateIfMeshRenderer
[InitializeOnLoad]
public static class IgnoreMeshFilterSharedMeshWhenMeshRendererExists {
	static ValidateMeshFilterSharedMesh() {
		MemberInfo sharedMeshMember = ValidatorUnityWhitelist.GetPropertyFrom(typeof(UnityEngine.MeshFilter), "sharedMesh");
		ValidatorPredicates.RegisterPredicateFor(sharedMeshMember, DontValidateIfMeshRenderer);
	}

	private static bool DontValidateIfMeshRenderer(object obj) {
		UnityEngine.Component component = obj as UnityEngine.Component;
		if (component == null) {
			return true; // should validate
		}

		MeshRenderer meshRenderer = component.GetComponent<MeshRenderer>();
		// should validate (true) when meshRenderer does not exist
		return meshRenderer == null;
	}
}

See the default included whitelisted classes (under DefaultIncluded/WhitelistedTypes) for more examples!


Q (advanced): I found an error that the validator doesn't mark as an error!

A: Is it a field on a Unity component? By default, nearly all Unity components are ignored by the validator because you can't mark fields as [Optional]. But you can pick specific type / field combinations for the validator to validate. Here's an example:

using DTValidator;

// This attribute lets Unity know to call the static constructor
// when the Editor starts up, therefore injecting MeshFilter->sharedMesh to be validated
[InitializeOnLoad]
public static class ValidateMeshFilterSharedMesh {
	static ValidateMeshFilterSharedMesh() {
		Type meshFilterType = typeof(UnityEngine.MeshFilter);
		MemberInfo sharedMeshMember = ValidatorUnityWhitelist.GetPropertyFrom(meshFilterType, "sharedMesh");
		ValidatorUnityWhitelist.RegisterWhitelistedTypeMember(meshFilterType, sharedMeshMember);
	}
}

See the default included whitelisted classes (under DefaultIncluded/WhitelistedTypes) for more examples!

Q (cont): It's not a field on a Unity component!

A: Open an issue with your specific case and I'll take a look at it 😁.


Don't see your question answered here? Open an issue!

More Repositories

1

DTCompileTimeTracker

Unity editor extension which tracks compile time
C#
210
star
2

finite-graph-machine

C# class with nodes / node delegates and a Unity editor that serializes all of that
C#
56
star
3

DTAnimatorStateMachine

Utility class for working with StateMachineBehaviours
C#
43
star
4

inverse-kinematics

4 joint IK solution generator in C++ and using OpenGL
C
23
star
5

DTCommandPalette

Command palette for Unity - run methods, open scenes, and more!
C#
19
star
6

DTMediaCapture

An API for recording video and taking screenshots.
C#
12
star
7

rspec-timing-splitter

Rust binary that parses rspecs timing information to split test files
Rust
11
star
8

wasm-rgame

Rust interface and types for wasm-gg
Rust
9
star
9

laserbeak

C#
9
star
10

DTLocalization

Localization API that supports GSpreadsheet backend, offline caching, much more!
C#
9
star
11

DTCoreModule

Shared scripts and resources module
C#
7
star
12

DTGameEngineModule

Basic scripts for building a game in Unity
C#
5
star
13

DTUIRebuildVisualizer

Tool to visualize UI canvas rebuilds and create performant Unity UI.
C#
5
star
14

interview-questions-in-unity

C#
4
star
15

wasm-rgame-js

wasm-gg javascript framework
JavaScript
3
star
16

wrg-snake

Snake implemented with the wasm-rgame framework.
Rust
2
star
17

atom_config

My atom configuration
CoffeeScript
2
star
18

nginx-hash-test

Playing around and verifying NGINX hash functionality.
Shell
2
star
19

raii-counter

Rust type for a RAII Counter implemented with Arc<AtomicUsize>
Rust
2
star
20

mastery-with-sql

Working through https://www.masterywithsql.com/ course.
TSQL
2
star
21

dt-unity-library

Personal library for developing unity games
C#
2
star
22

turbo-octopus

Untitled unity 2D sci-fi platformer rogue-like.
C#
1
star
23

swordy

C#
1
star
24

unity-burn-shader

1
star
25

DTArtificialIntelligenceModule

Implementations of use data structures for creating plausible Actors
C#
1
star
26

nn-and-dl-rs

http://neuralnetworksanddeeplearning.com/
Rust
1
star
27

alpha-zero-sandbox

Sandbox project to explore AlphaZero implementation
Rust
1
star
28

DTPrefabSandbox

Edit Prefabs quickly - in a sandbox!
C#
1
star
29

lazy-unity-helper

A non-efficient package for functions that help unity development
CoffeeScript
1
star
30

aoc-2018

https://adventofcode.com/2018
Rust
1
star
31

DTEasings

Lean API for easing functions and also optional extensions.
C#
1
star
32

ocean-breeze

shader implementation of sin wave movement on perlin noise in GLSL
C
1
star
33

unity-ascii-post-processing-effect

C#
1
star
34

wasm-validation-64

Test-case repository for wasm-bindgen issue (Validation error: Trying to access parent frame stack values.)
Rust
1
star
35

rust-pretty-assertions-sorted

Wrapper around the `rust-pretty-assertions` crate that allows for the ability to sort the Debug output.
Rust
1
star
36

DTObjectPoolManager

Object pooling framework
C#
1
star