Difference between class and TSubobjectPtr?

I think TSubobjectPtr is being phased out, but defintely don’t know.

“class” is just forward declaring the USphereComponent so that you don’t need to #include its declaration. However, you should put UPROPERTY() above the declaration of the Sphere pointer in so that UE4 knows to nullify the pointer when the object it points to is deleted. I think this is what TSubobjectPtr also does.

Just curious, I tried both of the below earlier and they both seem to work the same. I was just wondering if one had advantage over the other, or if one will soon be depreciated? I just want to be sure I’m getting used to doing things the best way.

TSubobjectPtr<USphereComponent> Sphere;

//Seems to work in the same nature as:

class USphereComponent* Sphere;

//^For header file. 

//Then in .cpp file constructor:

Sphere = CreateDefaultSubobject<USphereComponent>("Sphere", false);

Thanks for the explanation, I’ll stick w/ using class pointers for now. And yeah I’m using UPROPERTY() Macro, I should have included that in the example. I appreciate the prompt reply, have a good one :slight_smile: