Can anyone tell me what is the difference between the pointers in the UnrealEngine API and the native C++ pointers. Native pointers are easier to write and I prefer to use it, but are there any disadvantages compared to the TSubobjectPrt pointers?
They are smart pointers, when you destroy object normal pointer will point somewhere but not NULL which make it hard to check, smart pointers in UE4 API keep on track via UObject system if object been destroyed and clears all smart pointers pointing to it.
I see. So native pointers are not garbage collected by the engine?
They are if:
- They are UPROPERTY()
- Are somewhere in UObject derived class.
TSubobjectPtr is mainly used for default initialization in class constructor (where object need it’s own instance of other object), and by extension you can expose such instanced object back to editor, to edit it’s properties.
Though I wouldn’t take it to far and try to expose subobjects of subobjects ;).
Thank you very much, this is good to know