As far as I know,
UPROPERTY sets pointed object to added to GC reference graph, and prevent it from garbage collection.
Otherwise, the memory presented by TWeakObjectPtr can’t be prevented from garbage collecting.
Its purpose is similar to a raw pointer but different from using a raw pointer, it can detect the object destroyed.
But recently I found a code and I can’t understand the purpose.
USTRUCT()
struct FTileSetImportMapping
{
GENERATED_USTRUCT_BODY()
UPROPERTY()
FString SourceName;
// here
UPROPERTY()
TWeakObjectPtr<class UPaperTileSet> ImportedTileSet;
UPROPERTY()
TWeakObjectPtr<class UTexture> ImportedTexture;
};
This code was found in the engine code.
I want to know why UPROPERTY and TWeakObjectPtr are used together.