Can I use a factory method with a TSubObjectPtr?

For example, I have this TSubObjectPtr in my header:

UPROPERTY(blahblah)
TSubObjectPtr<class UTexture2D> myTexture;

Then in constructor, how do I assign it with a factory method such as:

myTexture = UTexture2D::CreateTransient(512,512);

Do I have to use native c++ pointers when using factory methods like:

UTexture2D *myTexture;

in the header instead?

Hi tkchen,

TSubobjectPtrs are meant to only be used for default subobjects constructed in the owning class constructor and theire purpose is to ‘own’ the pointer to the subobjects so that no derived classes can overwrite it. They’re also supposed to be used with ‘instanced’ objects (for example UActorComponents).

For assets, like textures, you should use normal pointers.