[UPDATE]
Ok, so the problem seems to be… WIDGETS.
I made 2 test classes, one AActor, and one UUserWidget.
With (almost) identical code, overriding the Serialize() method, to save additional NON UPROPERTY field values.
With both classes I added a UFUNCTION(CallInEditor) which changes those field values, and calls the Modify() method to signify that changes have been made.
With the actor, this works entirely as expected, the values are changed, and the level the actor is placed in gets the star(*) indicating it has unsaved changes. Saving and running the level shows the altered values were indeed persisted. As does reloading the editor.
Everything is fine.
With the Widget this is NOT the case. Calling Modify() seems to do nothing. It certainly does not set the widget blueprint with the star(*), and manually saving does NOT serialize the altered values (in fact it seems to reset them to defaults BEFORE serialization even happens)
If I override the Modify() method and add this:
UObject* WidgetBPObject = bIsEditorWidgetPreview ? WidgetTree_->RootWidget->WidgetGeneratedBy.Get() : WidgetTree_->GetOuter();
if (UUserWidgetBlueprint* WidgetBP = Cast<UUserWidgetBlueprint>(WidgetBPObject))
{
return WidgetBP->Modify(true);
}
else if (UUserWidget* UserWidget = Cast<UUserWidget>(WidgetBPObject))
{
return UserWidget->Modify(true);
}
(Which is based on code I ‘lifted’ from some other class in the editor)
Then the WidgetBlueprint DOES get a star(*) indicating that it has unsaved changes…
BUT the values which were modified are still not serialized.
Leaving me with the following questions:
- What is actually going on here?
- Why does this work one way for AActors, and is not consistent with UWidgets?
- How are we ‘supposed’ to modify UWidget values from code at edit time?