Unreal Headers to validate a variable?

Hi,

Are there any unreal Headers to quickly test the validation of a variable?
For example:

UPROPERTY(CannotBeNull)
FName NameOfWhatever;

This header would prevent compilation and log an error warning.

Pretty much like what DataValidation does, but without the hassle of having to write functions.
ie of how its currently handled:

EDataValidationResult AActor::IsDataValid(TArray<FText>& ValidationErrors)
{
	bool isValid = Super::IsDataValid(ValidationErrors) != EDataValidationResult::Invalid;

	if (NameOfWhatever == "") {
		ValidationErrors.Add(FText::FromString("Is missing field NameOfWhatever"));
		isValid = false;
}
	return isValid ? EDataValidationResult::Valid : EDataValidationResult::Invalid;
}

Also: same question but for fields/variables on instanced actors; ie.: actors placed in the level. I dont care if the field is null in the project, but the field cannot be null in the level.

Thanks <3

No, there is no declarator that will verify that some variable is never null.

1 Like

Would be nice to add this, maybe to FProperty or the BP compiler. Tons of c++ classes have to work with Blueprint dependencies (properties set from editor panel, blueprint class references, widget hierarchy, runtime data etc.), sometimes we just want to know if a property has been edited, is non default or any other state of “valid”.

If you want to enforce this use an assert if the field is null during gameplay to halt the process.

Asserts | Unreal Engine 4.27 Documentation

2 Likes

I would to like to precise I only care about the variable not being null in the editor at blueprint compilation time, at runtime I dont care.
If null it would prevent the compilation of the blueprint and log an error.