Updating Property Settings

So I’m probably going about this the wrong way but I’ve been trying to make a child class of AActor get data from a child class of UObject and have them somewhat synchronized. I did the following in my cpp file which works to make it so when I select an Item (the UObject Class) for the Pickup (the AActor class) it loads in all the data from the item’s CDO.

#if WITH_EDITOR
void APickup::PostEditChangeProperty(struct FPropertyChangedEvent& PropertyChangedEvent)
{
	Super::PostEditChangeProperty(PropertyChangedEvent);

	FName PropertyName = (PropertyChangedEvent.Property != NULL) ? PropertyChangedEvent.Property->GetFName() : NAME_None;
	if (PropertyName == GET_MEMBER_NAME_CHECKED(APickup, StorableItem))
	{
		if (StorableItem.Get())
		{
			UStorableItem* CDO = Cast<UStorableItem>(StorableItem->GetDefaultObject());
			Weight = CDO->Weight;
			bStackable = CDO->bStackable;
			StaticMesh->SetStaticMesh(CDO->StaticMesh);
			
		}
	}
}
#endif

However, if I then go into a StorableItem and change properties (like weight for instance) the pickup will still have the OLD property values from before I made the change which is the issue.

Am I going about this the wrong way or do I just need to add code to the item class to make it so when I update one of the variables it runs through a list of all the pickups in the asset browser and updates them as well?

Thanks,

I found the answer –

Set your UPROPERTY’s you want to copy from another class’s CDO as (Transient). This way, they don’t get serialized. Overwrite the ::Serialize(FArchive& Ar) UObject virtual function and set your Transient properties here.

void APickup::Serialize(FArchive& Ar)
{
	Super::Serialize(Ar);

	if (Item.Get())
	{
		UStorableItem* CDO = Item.GetDefaultObject();
		StaticMesh->SetStaticMesh(CDO->GetStaticMesh());
	}
}

Where StaticMesh is a Transient UStaticMeshComponent. Item is a TSubclassOf. Make sure you do this after you Super:: so that your TSubclassOf is updated before copying data from it’s CDO. This is the best solution I could find.