How can I stop the Garbage Collector from removing a UTexture2D?

private:
UPROPERTY()
UTexture2D *Texture;

Is indeed the correct way

Use UPROPERTY to tell the UE4 GC system to leave your texture, or any spawned/ new object asset alone :slight_smile:

Null out the reference when you are ready to have it GC’ed

Texture = nullptr;

#Wiki Tutorial on GC and Dynamic Memory Management

1 Like