# Is there a way to prevent instantiating objects using NewObject?

**URL:** <https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [July 19, 2019, 11:59am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926 "2019-07-19T11:59:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![herob4u](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@herob4u](https://forums.unrealengine.com/u/herob4u)\
**Post date:** [July 19, 2019, 11:59am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926/1 "2019-07-19T11:59:38Z")

</div>

As far as I am concerned, the UObject system would require a default constructor to be defined - primarily for the sake of creating the CDO.  
Knowing that, is there a way to prevent users from instantiating a certain class using the NewObject method? Bottom line is, I am trying to delegate the instantiation to a factory method.

I have tried setting the constructor to be **protected** , and included the \*\*customConstructor \*\*specifier for my UClass. However, instantiating the object threw no compile time errors or warnings.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [July 19, 2019, 1:01pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926/2 "2019-07-19T13:01:32Z")

</div>

Do not export the class with XXXX\_API.

​​Or do UCLASS(MinimalAPI)  
Or UCLASS(Abstract)

---

<div class="post-metadata">

**Author:** ![herob4u](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@herob4u](https://forums.unrealengine.com/u/herob4u)\
**Post date:** [July 19, 2019, 2:35pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926/3 "2019-07-19T14:35:07Z")

</div>

> [@BrUnO\_XaVIeR](#):
>
> Do not export the class with XXXX\_API.
> 
> ​​Or do UCLASS(MinimalAPI)  
> Or UCLASS(Abstract)

I believe abstract would prevent my factory method from instantiating it as well? As for MinimalAPI and not exporting - does that not mean I cannot work with the object in the editor (cannot be exposed to BP)? Either ways it seems like the solution is pushing me to create a base abstract class.

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [July 19, 2019, 2:52pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-prevent-instantiating-objects-using-newobject/128926/4 "2019-07-19T14:52:09Z")

</div>

Yes I would create an abstract base class.
