#you mean like `PostEditChangeProperty`?
1 messages · Page 1 of 1 (latest)
There's also that which you can try, but no I'm talking about data validators which are different, let me fetch an example
#include "CoreMinimal.h"
#include "EditorValidatorBase.h"
#include "ItemsDTValidator.generated.h"
/**
*
*/
UCLASS()
class PROLOGUEEDITOR_API UMyDAValidator : public UEditorValidatorBase
{
GENERATED_BODY()
public:
virtual bool CanValidateAsset_Implementation(const FAssetData& InAssetData, UObject* InObject, FDataValidationContext& InContext) const override;
virtual EDataValidationResult ValidateLoadedAsset_Implementation(const FAssetData& InAssetData, UObject* InAsset, FDataValidationContext& Context) override;
};
bool UMyDAValidator::CanValidateAsset_Implementation(const FAssetData& InAssetData, UObject* InObject, FDataValidationContext& InContext) const
{
// Put your condition here so that the data validator only runs on your class
if (InAssetData.AssetClassPath != UDataAsset::StaticClass()->GetClassPathName())
{
return false;
}
const UDataAsset* DA = Cast<UDataAsset>(InObject);
if (!ensure(DA != nullptr))
{
return false;
}
return //DA->... Do some checks;
}
EDataValidationResult UItemsDTValidator::ValidateLoadedAsset_Implementation(const FAssetData& InAssetData, UObject* InAsset, FDataValidationContext& Context)
{
const UDataAsset* DA = Cast<UDataAsset>(InAsset);
if (!ensure(DA != nullptr))
{
return EDataValidationResult::NotValidated;
}
// We don't return when asset fails so all the errors will be shown
DA->ForAllTheThingsInAnArry<FThingInMyDA>("Items DT Validator", [this, InAsset](const FName Key, const FThingInMyDA& Data) {
if (Data.SomeInternalInt < 10)
{
AssetFails(InAsset, FText::Format(FTextFormat::FromString(FString("Item {0} needs its int to be >= 10")), FText::FromName(Key)));
}
// More checks
});
return GetValidationResult() == EDataValidationResult::Invalid ? EDataValidationResult::Invalid : EDataValidationResult::Valid;
}
Thanks I appreciate it, will look into this rn!
Essentially all I need is a hook after/when a data asset gets modified
It's super nice to have errors show up when saving data (I've used it for data tables mostly tbh, maybe the one you shared before works fine if you do your own DA type)
I think this specific class is meant to check whether the data is valid, but I believe there's another one (or maybe even this one) which can actually modify the asset, so if someone puts an int to 10 when the max is 9, it can correct it to be 9 (terrible example ofc, you can just use the UPROPERTY meta tags to do that)
"Essentially all I need is a hook after/when a data asset gets modified "
for this use case I'm not sure if it'll help though. Why do you want to do that ? 😮
I need to read/process the data asset after it gets saved/modified. Ideally it would be on modify without having to save but it's not crucial
I don't actually need to modify the data asset itself though
as you said UPROPERTY meta tags do the job when it comes to simple validty checks
"I need to read/process"
but you don't want to modify it ? I'm confused x) is it to check the validity or to do something more complex ?
PostEditChangeProperty seems like a very solid option though if you have access to it (which isn't the case for data tables)
yep, I guess you could say it's more complex but basically I just need to access the data asset after it got modified, I don't need to do further modification on the asset itself though
maybe
If you do use PostEditChangeProperty, here's a simple example:
where ActorHealth is a property of AMyActor
void AMyActor::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
if (PropertyChangedEvent.GetPropertyName() == GET_MEMBER_NAME_CHECKED(AMyActor, ActorHealth))
{
// Do something when actor health changes
}
}
this way you can easily pinpoint what properties are being modified and do w/e you need based on this