# TSubobjectPtr vs Native C++ Pointer

**URL:** <https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675>\
**Category:** C++\
**Tags:** unreal-engine, CPP, question, pointers\
**Created:** [June 24, 2014, 6:16pm UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675 "2014-06-24T18:16:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dbrizov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dbrizov](https://forums.unrealengine.com/u/dbrizov)\
**Post date:** [June 24, 2014, 6:16pm UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675/1 "2014-06-24T18:16:49Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Shadowriver](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Shadowriver](https://forums.unrealengine.com/u/Shadowriver)\
**Post date:** [June 24, 2014, 7:53pm UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675/2 "2014-06-24T19:53:54Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dbrizov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dbrizov](https://forums.unrealengine.com/u/dbrizov)\
**Post date:** [June 25, 2014, 4:00am UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675/3 "2014-06-25T04:00:08Z")

</div>

I see. So native pointers are not garbage collected by the engine?

---

<div class="post-metadata">

**Author:** ![iniside](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/iniside/32/866315_2.png) [@iniside](https://forums.unrealengine.com/u/iniside)\
**Post date:** [June 25, 2014, 7:40am UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675/4 "2014-06-25T07:40:04Z")

</div>

They are if:

1. They are UPROPERTY()
2. 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 ;).

---

<div class="post-metadata">

**Author:** ![dbrizov](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dbrizov](https://forums.unrealengine.com/u/dbrizov)\
**Post date:** [June 25, 2014, 7:51am UTC](https://forums.unrealengine.com/t/tsubobjectptr-vs-native-c-pointer/286675/5 "2014-06-25T07:51:06Z")

</div>

Thank you very much, this is good to know 🙂
