Refreshing editor after property change?

Using the following code I want to reset an object’s properties to defaults (CDO).
It appears the value on the memory address of the CDO is copied correctly to the target, but the editor window does not update. Properties on the editor panel show the old values and the yellow “reset to default” icons are still displayed. Running FKismetEditorUtilities::CompileBlueprint on the parent object does not fix this. Hitting the compile button manually does. What am I missing?

const UObject* DefaultObject = InTargetWidget->StaticClass()->GetDefaultObject();
for (TFieldIterator<FProperty> PropertyIterator(InTargetWidget->StaticClass()); PropertyIterator; ++PropertyIterator) {
	FProperty* PropertyX = *PropertyIterator;
	if (!PropertyX) {
		continue;
	}

#if WITH_EDITOR

	if (!CanManageProperty(PropertyX)) {
		continue;
	}

#endif // WITH_EDITOR

	void* CurrentValueAddress = PropertyX->ContainerPtrToValuePtr<void>(InTargetWidget);
	const void* DefaultValueAddress = PropertyX->ContainerPtrToValuePtr<void>(DefaultObject);

#if WITH_EDITOR

	InTargetWidget->PreEditChange(PropertyX);

#endif // WITH_EDITOR

	PropertyX->CopyCompleteValue(CurrentValueAddress, DefaultValueAddress);

#if WITH_EDITOR

	FPropertyChangedEvent PropertyEvent(PropertyX);
	InTargetWidget->PostEditChangeProperty(PropertyEvent);

#else // Not WITH_EDITOR

	// Still need to synchronize the widget, which is otherwise done during PostEditChangeProperty.
	TSharedPtr<SWidget> SafeWidget = InTargetWidget->GetCachedWidget();
	if (SafeWidget.IsValid()) {
		InTargetWidget->SynchronizeProperties();
	}

#endif // WITH_EDITOR

}

After more testing I found out that calling this at the wrong moment can lead to memory violations. What is the correct way to just refresh the editor after modifying property memory of an object it is showing?

Tried this, still nothing:

TSharedPtr<IBlueprintEditor> X = FKismetEditorUtilities::GetIBlueprintEditorForObject(ParentBlueprint, false);
X->RefreshMyBlueprint();
X->RefreshEditors();
X->RefreshInspector();
X->RegenerateMenusAndToolbars();
1 Like

This is now irrelevant.
After getting the default value using a different method (“ContainerPtrToValuePtrForDefaults”), “PostEditChangeProperty” did the refresh as was expected the first time.

1 Like

Try this:

#include "Modules/ModuleManager.h"
#include "PropertyEditorModule.h"

// after you modify the memory
FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");
PropertyModule.NotifyCustomizationModuleChanged(); // this will eventually call DetailViewPin->ForceRefresh() for all panels

Works for me in 4.26.2

1 Like