I have a custom instanced (default to instanced, edit inline new) UObject property that is a drop-in helper for generating a stable FGuid for each object it belongs to within a level.
The goal is to generate the FGuid ONCE and then have it stay the same between sessions. I can’t generate the FGuid from actor path or name because those are unreliable. The property is declared like this where ever it is needed:
UPROPERTY(EditInstanceOnly, Instanced)
TObjectPtr<UStableIdProvider> IdProvider{nullptr};
The UStableIdProvider instance is instantiated in the constructor with CreateDefaultSubObject. It has one UPROPERTY:
UPROPERTY(EditAnywhere)
FGuid StableId;
I am using PostInitProperties to ensure the Id is valid, but only if it isn’t invalid (and only on instances, not on the template).
void UStableIdProvider::PostInitProperties()
{
Super::PostInitProperties();
if (!IsTemplate() && !StableId.IsValid())
StableId = FGuid::NewGuid();
}
However if I modify the owning actor/component in any way, the value ‘churns’ (I have logged the value and it continually changes while edits are being made).
I’ve tried using PostEditImport and PostLoad to do the same thing. But they don’t appear to trigger the FGuid generation at all.
I’m completely lost on how to generate this value once exactly for any level actor/component and then save that value so it’s consistent between sessions. It would need to generate on adding the actor to the level (either that or somehow tell the editor the actor needs to be saved once generated).
Please help D: