Skip to content

Instantly share code, notes, and snippets.

@DashW
Created November 4, 2020 12:50
Show Gist options
  • Save DashW/b6d08f89cfc6f558b99c7a1b99edf5fd to your computer and use it in GitHub Desktop.
Save DashW/b6d08f89cfc6f558b99c7a1b99edf5fd to your computer and use it in GitHub Desktop.
Class definition for Unreal's Base Editor Validator. All code belongs to Epic Games and is available from their GitHub.
/*
* The EditorValidatorBase is a class which verifies that an asset meets a specific ruleset.
* It should be used when checking engine-level classes, as UObject::IsDataValid requires
* overriding the base class. You can create project-specific version of the validator base,
* with custom logging and enabled logic.
*
* C++ and Blueprint validators will be gathered on editor start, while python validators need
* to register themselves
*/
UCLASS(Abstract, Blueprintable, meta = (ShowWorldContextPin))
class DATAVALIDATION_API UEditorValidatorBase : public UObject
{
GENERATED_BODY()
public:
UEditorValidatorBase();
/** Override this to determine whether or not you can validate a given asset with this validator */
UFUNCTION(BlueprintNativeEvent, Category = "Asset Validation")
bool CanValidateAsset(UObject* InAsset) const;
UFUNCTION(BlueprintNativeEvent, Category = "Asset Validation")
EDataValidationResult ValidateLoadedAsset(UObject* InAsset, UPARAM(ref) TArray<FText>& ValidationErrors);
UFUNCTION(BlueprintCallable, Category = "Asset Validation")
void AssetFails(UObject* InAsset, const FText& InMessage, UPARAM(ref) TArray<FText>& ValidationErrors);
UFUNCTION(BlueprintCallable, Category = "Asset Validation")
void AssetPasses(UObject* InAsset);
virtual bool IsEnabled() const
{
return bIsEnabled;
}
void ResetValidationState();
bool IsValidationStateSet() const
{
return ValidationResult != EDataValidationResult::NotValidated;
}
UFUNCTION(BlueprintCallable, Category = "Asset Validation")
EDataValidationResult GetValidationResult() const
{
return ValidationResult;
}
protected:
void LogElapsedTime(FFormatNamedArguments &Arguments);
protected:
UPROPERTY(EditAnywhere, Category = "Asset Validation", meta = (BlueprintProtected = "true"))
bool bIsEnabled;
private:
EDataValidationResult ValidationResult;
FDateTime ValidationTime;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment