# Is it possible to forward declare TUniquePtr?

**URL:** <https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946>\
**Category:** C++\
**Tags:** variables, Struct, unreal-engine, UE5-0, question\
**Created:** [May 9, 2022, 5:14pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946 "2022-05-09T17:14:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [May 9, 2022, 5:14pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946/1 "2022-05-09T17:14:38Z")

</div>

Hi,

This compiles fine using TSharedPtr  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/b/61b0d2a5f0a2fbde80912fe893ff8f336133b87c.png)

in CPP  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/a/37aed63b3752317e4ae9b04cce46dd7fbc8d81fd.png)

However changing to TUniquePtr doesn’t compile  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/5/4051ca609604b2359153d305ec3cba5ad1bfcaf7.png)

CPP  
 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/0/8204a781d517693bce591dabd1c9988325f07f64.png)

![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/7/3/473bfce8254046c891ac0f16cdcd1bd4893daca2.png)

I understand I have to include the header file where that struct exists but is there no way to forward declare with uniquePtr while it’s possible with shared ptr ?  
PS: I have the header file included in the CPP I just don’t want to have it included in the header file.

Thank you.

---

<div class="post-metadata">

**Author:** ![gpetit-sew](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gpetit-sew](https://forums.unrealengine.com/u/gpetit-sew)\
**Post date:** [July 31, 2022, 9:05pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946/2 "2022-07-31T21:05:58Z")

</div>

Yes, it is possible;

In `UniquePtr.h` you will find the following comment:

```auto
// If you get an error here when trying to use a TUniquePtr<FForwardDeclaredType> inside a UObject then:
//
// * Declare all your UObject's constructors and destructor in the .h file.
// * Define all of them in the .cpp file. You can use UMyObject::UMyObject() = default; to auto-generate
// the default constructor and destructor so that they don't have to be manually maintained.
// * Define a UMyObject(FVTableHelper& Helper) constructor too, otherwise it will be defined in the
// .gen.cpp file where your pimpl type doesn't exist. It cannot be defaulted, but it need not
// contain any particular implementation; the object just needs to be garbage collectable.
//
// If this is efficiency is less important than simplicity, you may want to consider
// using a TPimplPtr instead, though this is also pretty efficient too.

```

Essentially, you need to have your constructor and destructor declared in your `.h` and implemented in your `.cpp`, and if you rely on a`.generated.h` you also need the constructor with `FVTableHelper& Helper`.

When you don’t, then the compiler still generates these constructors/destructors in the header file for you, and the destructor will refer to the constructors and destructor of `TUniquePtr` which needs to know about the constructors and destructor of your `FRepDataDudu` type - causing the compilation error if you only forward declared your type.

---

<div class="post-metadata">

**Author:** ![KaidoomDev](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaidoomdev/32/977996_2.png) [@KaidoomDev](https://forums.unrealengine.com/u/KaidoomDev)\
**Post date:** [July 31, 2022, 10:59pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946/3 "2022-07-31T22:59:26Z")

</div>

Thank you for the solution I appreciate it.

---

<div class="post-metadata">

**Author:** ![Luomu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Luomu](https://forums.unrealengine.com/u/Luomu)\
**Post date:** [February 12, 2026, 6:28pm UTC](https://forums.unrealengine.com/t/is-it-possible-to-forward-declare-tuniqueptr/552946/4 "2026-02-12T18:28:41Z")

</div>

Interestingly I wasn’t able to use this with a GameInstanceSubsystem, even after defining & declaring all of:  
`UMySubsystem();`  
`UMySubsystem(const FObjectInitializer);`  
`~UMySubsystem();`  
`UMySubsystem(FVTableHelper& Helper);`

However, TPimplPtr mentioned in that TUniquePtr header worked nicely, so consider it if you happen upon this same problem, and if it fits your use case.

`#include "Templates/PimplPtr.h"`  
`TPimplPtr<FMyForwardDeclaredType> Foo;`  
`Foo = MakePimpl<FMyForwardDeclaredType>();`
