How to handle property updates in code?

I have a custom Actor class, and a couple of derived blueprints with specific defaults.
I am initializing Components with these new defaults inside overridden OnConstruction, and it works. However, I would also like to change blueprint properties in real time and see the effect immediately, how can I achieve this?.

I would like to know as well. Is there a callback in the component for when a property has been changed in the editor? Thanks!

After some forum searching, I have found some functions which handle object property updates: PostEditChangeProperty for regular UProperties and PostEditChangeChainProperty for TArrays.
They are invoked as follows:

//for regular properties:
void ACustomClass::PostEditChangeProperty(struct FPropertyChangedEvent& e)
{
	FName PropertyName = (e.Property != NULL) ? e.Property->GetFName() : NAME_None;
	if (PropertyName == GET_MEMBER_NAME_CHECKED(UCustomClass, PropertyName))
	{
        //various uproperty tricks, see link
	}
    Super::PostEditChangeProperty(e);
}

//for TArrays:
void ACustomClass::PostEditChangeChainProperty(struct FPropertyChangedChainEvent& e)
{
    int32 index = e.GetArrayIndex(TEXT("Meshes")); //checks skipped
    UStaticMesh *mesh = Meshes[index]; //changed mesh
    Super::PostEditChangeChainProperty(e);
}

Retrieved from these links:
PostEditChangeChainProperty,
PostEditChangeProperty

On UProperty manipulation: Access Blueprint vars from c++ q1, Access Blueprint vars from c++ q2

Unfortunately, I have yet to figure out how to trace component property changes. There is, however, a rather obscure delegate (FCoreDelegates::OnObjectPropertyChanged), which might be configured to call your function on component property updates. For me, it does not work. Maybe it would be easier just to use a custom component class with overridden PostEditChangeProperty.

4 Likes

This is awesome, thank you so much.

Dude, thanks! this is super useful information!

Yes it does only work in editor and need to have #if WITH_EDITOR in both H and CPP files

1 Like

Doesn’t it work only inside of Editor?..

I will add that it must be #if and not #ifdef because WITH_EDITOR is always declared.
Also #endif should be put at the end, in case somebody doesn’t know.
Here’s an example, probably one of the very few you will find nowadays in the docs: AActor::PostEditChangeProperty | Unreal Engine Documentation

1 Like

Declare them in the header like this:
virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;