An Unreal OnValidate Equivalent?

Hey all,

I made the switch to from Unity to Unreal during the dark times last year and am loving it so far with the caveat of executing easily accessible editor functionality, specifically an equivalent of Unity’s OnValidate function for use the in Blueprint Editor (note: not an instance in the game world, in the Blueprint Editor).

My use case is a game with many assets and components that share property values (mesh collision type, material, physics and render settings (you get the idea)). I’d like my artist and designers to not worry about manually setting or forgetting those in each blueprint or accidentally editing them. These assets use compound mesh components (both static and skeletal) so we can’t rely on inheritance to do it once.

We’d want to avoid doing this at runtime during construction for performance reasons, There’s simply no need to hundreds or even thousands of the assets and components to not be preconfigured in editor.

Unity’s OnValidate was the ideal function for achieving this level or validation. I could respond to changes in Prefabs and provide warnings, confirmation popups or reset the value.

So far I have not found a comparable and accessible Unreal alternative. Maybe on PreSave, PreEditChange and Modify UObject overrides? However, my goal would be to have this functionally exist in Blueprints where a designer could easily adjust settings in a friendly environment rather than return to c++ for each modification.

What’s maddening is I’m seeing exactly what I want from the PreConstruct event on UserWidgets! A Blueprint event that runs in Editor and can be used to modify and validate components and properties.

Is there a feature I’ve completely overlooked which would allow this?

TLDR: Is there an Unreal OnValidate equivalent that can be used in the Blueprint Editor?

The closest i would think is Editor Utility Blueprint, these bp only run through editor.

Example:


image

There might be other function to look at because i think you are looking for an auto loaded script during import of an asset mesh, texture.

1 Like

Thanks, but Data Validation does not seem to be a suitable alternative. I checked it out since the name implies similar functionality. But from what I can tell it’s not made to modify Blueprint and/or Blueprint Component properties (particularly as they’re being edited).

Data validation can change properties with UE::DataValidation::IFixer

But if you just want to change some properties while editing other property, you can use UObject::PostEditChangeProperty

1 Like

Whoa, this could be it. I’ll check it out. Thanks!

I’ll check this out. It look promising but as you say I’m after something autoloaded that can respond to property changes on the blueprint as they happen.

PreEditChange and Modify overloads do this, I just need to work out how to set these default validated values if they’ve changed on a Blueprint.

I feel like I’m so close too, I have a PreEditChange and PreSave calling a BlueprintNativeEvent which in turn logs to the console but most functions don’t work outside of runtime.

See below:

.h

UCLASS(Blueprintable)
class FOO_API AFoo : public AActor
{
...
#if WITH_EDITOR
	virtual void PreSave(FObjectPreSaveContext SaveContext) override;
	virtual void PreEditChange(FProperty* PropertyAboutToChange) override;
#endif
...
	UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = "Validator")
	bool Validate();
	virtual bool Validate_Implementation();
};

.cpp

#if WITH_EDITOR
void AFoo ::PreSave(FObjectPreSaveContext SaveContext)
{
	Validate();
	Super::PreSave(SaveContext);
}

void AFoo ::PreEditChange(FProperty* PropertyAboutToChange)
{
	Validate();
	Super::PreEditChange(PropertyAboutToChange);
}
#endif

BP

Log

LogBlueprintUserMessages: [Default__BP_Foo_C] Validate
LogScript: Warning: Script Msg: No world was found for object (/Game/Foo/BP_Foo.Default__Foo_C) passed in to UEngine::GetWorldFromContextObject().
LogScript: Warning: Script Msg called by: BPFL_Foo_C /Game/Foo/Libraries/BPFL_Foo.Default__BPFL_Foo_C

As you can see from logs there is no world reference for some functions (in this case a BlueprintFunctionLibrary)

I’ve been using PreSave and PreEditChange to trigger a validator function as seen above. If this is indeed the common UE practice I’ll if I can resolve my issue of some functions requiring a world reference and continue down that path.

Update: It is not the common UE practice. No blueprint functions work :confused:

Haven’t found an easily accessible and comparable feature to Unity’s OnValidate function that meets our needs. Not one that achieves the desired results without needing to go to extreme lengths.

So far I’ve looked at:

  • Blueprint Construction.
    • Cannot set property values of Blueprint Assets in the Blueprint Editor during editor mode.
    • Executed at runtime invalidating entire process.
  • PreSave, PreEditChange or PostEditChange overrides.
    • Only work in C++, executing BlueprintNativeEvents causes the same issues as Blueprint Constructors.
  • Batch edit in the property matrix.
    • Not automated.
    • Only works when assets share exacting properties.
      • Differing child components and numbers of child components do not appear in matrix.
  • Data Validation & Editor Blueprint Utilities.
    • Cannot cast Asset Objects to Blueprint types to modify properties on themselves or their child components.
    • Editor Blueprint Utilities are not automated.

Unless I’m missing something exceedingly esoteric, you can’t modify an Actor Blueprint Asset’s properties or that of its components. I’ve been trying to find any example of an Editor Unity of any kind modifying a Blueprint Asset’s components and have come up short. It seems you need to have your BP’s inherit from C++ or use a Python Script to get anything close to a validator, both of which will alienate artists and designers. Well I guess that keeps engineers employed.

Fixed using the Subobject Data Subsystem!

On an Editor Validator, you can pass the asset to the Subobject Data Subsystem as a Blueprint to iterate over all components and validate or modify their properties.

It’s a shame this is more well documented and most tutorials on the subject have the user simply modifying assets without components.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.