# Difference between TWeakPtr and TWeakObjectPtr?

**URL:** <https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467>\
**Category:** C++\
**Tags:** unreal-engine, UE4, question, CPP\
**Created:** [September 8, 2015, 4:23pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467 "2015-09-08T16:23:56Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [September 8, 2015, 4:23pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/1 "2015-09-08T16:23:56Z")

</div>

What is the difference between TWeakPtr and TWeakObjectPtr?

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 8, 2015, 5:16pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/2 "2015-09-08T17:16:05Z")

</div>

TWeakObjectPtr is for weak pointers to UObjects, TWeakPtr for pointers to everything else.

Since UObjects are garbage collected and shared pointers are reference counted, we cannot have the same weak pointer type for all, unfortunately.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [September 8, 2015, 7:06pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/3 "2015-09-08T19:06:22Z")

</div>

Thanks! Did you mean _garbage collected_?

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 8, 2015, 7:54pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/4 "2015-09-08T19:54:55Z")

</div>

Weak pointers do not affect garbage collection. If the pointed to object has been deleted, the weak pointer will be invalid. This is true for both UObjects and non-UObject (TSharedPtr) objects.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_08c2fdfc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_08c2fdfc](https://forums.unrealengine.com/u/anonymous_user_08c2fdfc)\
**Post date:** [September 8, 2015, 11:06pm UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/5 "2015-09-08T23:06:17Z")

</div>

Sorry I made a typo myself (see my edit on my comment)… Thank you for the explanations.

---

<div class="post-metadata">

**Author:** ![gmpreussner\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gmpreussner\_1](https://forums.unrealengine.com/u/gmpreussner_1)\
**Post date:** [September 9, 2015, 1:05am UTC](https://forums.unrealengine.com/t/difference-between-tweakptr-and-tweakobjectptr/331467/6 "2015-09-09T01:05:01Z")

</div>

Thanks, fixed
