Asset Validator (Python)
Implementing an Editor Asset Validator in Python
The following is a functional skeletal example of an Editor Asset Validator class in Python.
Notice how the class uses @unreal.uclass() and @unreal.ufunction() decorators to be treated as a valid UClass (see UClass Decorators)
import unreal
# Sample implementation of an Editor Asset Validator in Python
@unreal.uclass()
class EditorValidatorConcrete(unreal.EditorValidatorBase):
def __init__(self, *arg, **kwds):
super(EditorValidatorConcrete, self).__init__(*arg, **kwds)
# Tests an asset for validity and either
# passes (by calling self.asset_passes and returning VALID)
# or fails (by calling self.asset_fails and returning INVALID)
#
# WATCH OUT!: This ufunction has two return values, because the parameter
# validation_errors is marked as pass-by-reference in the parent - UPARAM(ref)
@unreal.ufunction(override=True)
def validate_loaded_asset(self, asset, validation_errors):
self.asset_fails(asset, "asset failed", validation_errors)
return (unreal.DataValidationResult.INVALID, validation_errors)
# Tests an asset's type or properties to discern
# whether it should be validated by this class
@unreal.ufunction(override=True)
def can_validate_asset(self, asset):
return True
# Unlike EditorValidatorBase subclasses in C++, which are registered automatically,
# EditorValidatorBase subclasses in Python must be registered manually:
if __name__ == "__main__":
editor_validator_subsystem = unreal.get_editor_subsystem(unreal.EditorValidatorSubsystem)
validator = EditorValidatorConcrete()
editor_validator_subsystem.add_validator(validator)
For more information on Asset Validators, see the following pages of the Unreal Engine Documentation: