Creating a robust blueprint and asset validation in Unreal using Python.

Unreal Engine has a ton of tools to make more efficient and manageable workflows for its developers with one of the most popular being its validation. There are two main ways to create validation for your projects. The first is having a custom UObject-derived class that overrides IsDataValid and the second is what I'm going to be talking about - using UEditorValidatorBase derived from either C++ or Python to filter custom conditions.
Part 1: Implementation
It's important to use your own judgement when deciding on adding Save/Submit validators for your project. Likewise make sure if you use any external source control software to also add a verification for changelists that might require these validation. Below is an example of what implementing either of these validators might look like.
@unreal.uclass()
class SaveValidator(unreal.EditorValidatorBase):
def __init__(self, *arg, **kwds):
super(TSBPSaveValidator, self).__init__(*arg, **kwds)
@unreal.uclass()
class SubmitValidator(unreal.DirtyFilesChangelistValidator):
def __init__(self, *arg, **kwds):
super(TSBPSubmitValidator, self).__init__(*arg, **kwds)
We can then filter out what type of assets we wish to validate. In the example below I have this validator only run on Blueprints but this can easily be replaced with assets, audio files, or textures.
@unreal.ufunction(override=True)
def can_validate_asset(self, asset:unreal.Object):
if asset.get_default_object() in [unreal.Blueprint.get_default_object()]:
return True
Now we can start making functions to handle these conditional requirements. Remember to first retrieve the class type from the generated class if you wish to run any checks internally. An example you could add is making sure that if the Gameplay Effect has a cooldown it has a valid Gameplay Cue alongside it.
if unreal.get_type_from_class(check_asset.generated_class()) == unreal.GameplayEffect:
That's all there is to it. You can also make a C++ library alongside this to access even more custom and bespoke requirements. I personally think every project should have some form of validation and this provides an automated alternative to blueprint and asset reviews that might not be as prioritised in small teams.