UE5 Data Validation Intro
Introduction
When working in a bigger team and the asset count keeps growing it can be useful to have automated pipelines to ensure that assets are following project wide conventions.
Take these audio related use cases for example:
-
ensure assets (
SoundWave
,MetaSound
,SoundCue
) have specificAttenuation
,SoundClass
,Priority
settings before they are checked into source control - ensure audio related assets follow the project specific naming conventions
- enusure custom audio gameplay related components have all their dependencies setup and are configured correctly
Unreal Engine ships with the Data Validation Plugin
,
which is enabled by default.
In it's simplest use case, it allows to create custom asset validators
by creating an
Editor Utility Blueprint
(EUW
) that derives
from EditorValidatorBase
.
Additionally you can also create these in Python
and
C++
, and any
UObject
derived class can override a virtual IsDataValid
method
to perform validation checks on private/protected class properties.
In this article we're going to create a simple Blueprint based validator. For subsequent articles I will be tackling python and C++.
Asset Validation can be invoked on a per asset basis, an entire folder from the content browser or via the following commandlet:
> UnrealEditor-Cmd.exe <PROJECT_NAME>.uproject -run=DataValidation
NOTE: For the following example we'll be using the Lyra Starter Game
Creating a Editor Utility Blueprint Validator
Our simple validator will check if SoundBase
derived
asset has a valid SoundClass
.
First we need to create an EditorUtilityWidget
that
derives from EditorDataValidatorBase
. For simplicity,
lets name it BP_SoundBase_Validator
.
In our Blueprint there are 3 functions we need to override.
CanValidate
CanValidate
controls for which use case the data
validator will run.
You can just return true
to have it run always or select
specific use cases.
For demonstration purposes this validator will run when
Manual
validation is performed using the context menu,
via the Commandlet
and on Save
.
CanValidateAsset
CanValidateAsset
controls for which
asset types this validator should run. We take the
InAsset
and cast it to SoundBase
, you can
right click the regular cast to node and convert it to a
pure cast
to get a boolean
success result we can plug into the return node.
NOTE: This is just a very basic example, you could for instance use the
get asset path
node on theInAsset
and restrict a validator to only run in a certain sub-folder of your project.
ValidateLoadedAsset
Finally, in ValidateLoadedAsset
we implement the actual
data validation procedure.
In our simple example we again cast the InAsset
to
SoundBase
then we get the SoundClass and check if it is
valid
.
NOTE: It's important that every execution path calls either
AssetPasses
,AssetFails
orAssetWarning
before returning the validation result!
NOTE: Blueprint and C++ validators get registered with the DataValidation Subsystem automatically, but require an editor restart before they start working.
After restarting the editor we can test the validator by selecting any
SoundBase
derived assets like SoundWave
,
SoundCue
or MetaSound
or folder in the
content browser and running
Asset Actions -> ValidatAssets
or
Validate Assets in Folder
from the context menu.
NOTE: This is just a very simple example. It's up to you to identify the areas of your project where validation can be useful.
One important thing to keep in mind is to keep error messages useful, so your team members know how to fix issues that surfaced by the validation.
Otherwise you run the risk of adding unnecessary friction to the iteration process of your team!