# Properly using NewObject

**URL:** <https://forums.unrealengine.com/t/properly-using-newobject/289717>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [July 30, 2014, 5:59pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717 "2014-07-30T17:59:30Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 30, 2014, 5:59pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/1 "2014-07-30T17:59:30Z")

</div>

Hi guys,

I have a UObject-inheriting class here:

![11497-ghsdgdghh.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/7/8/378dd9794b787ca7dcbc9548804440f5143ad217.jpeg)

As you can see, I have an implementable event there. My idea is that I inherit several classes from this one using blueprints, and implement this event differently in each of them. So, I created a function that accepts a subclass of this UTalent class, creates object of this subclass and calls its ReceiveInit function:

![11499-sdcfasdfl.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/4/0/d/40d84fa04c2d34cf7a7e1338c59ffa7ad464a8d7.jpeg)

However, when I create a Blueprint which inherits from UTalent, and call this AddTalent func from blueprint, passing the created blueprint’s class as argument, the ReceiveInit is not being called.

When I dug deeper, I found out that my way of using NewObject, apparently, creates simply a UTalent object, instead of instance of my blueprint’s class. I found it out simply by changing some properties in inherited class. While debugging AddTalent func, I saw that talent object has same property that were set in UTalent class, and not the ones in my blueprint class. So, am I using the NewObject wrong, and how to properly create an UObject using a TSubClassOf thing?

---

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 30, 2014, 6:04pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/2 "2014-07-30T18:04:44Z")

</div>

To clearify things a little bit, here is a blueprint class that I inherited and my call to AddTalent func with that class as argument (which apparently still creates an UTalent object):

 ![11511-fasd;flkjf.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/b/e/9bef5e09085906d40ab4c175e61bc8ab9421d6df.jpeg)

 ![11512-rfasfsfg.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/f/b/3fb4944eb38e58b5f9c95152c8366c8553f2a49f.jpeg)

---

<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:** [July 30, 2014, 6:28pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/3 "2014-07-30T18:28:20Z")

</div>

Try ConstructObject insted of NewObject

**This anwser is outdated** use NewObject(SomeParent\_CanBeSimplyThis,UClass\*)

---

<div class="post-metadata">

**Author:** ![Lordink](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Lordink](https://forums.unrealengine.com/u/Lordink)\
**Post date:** [July 30, 2014, 8:58pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/4 "2014-07-30T20:58:39Z")

</div>

WORKS! Thanks, man. Always thought that ConstructObject is just a slower and more specific way of creating uobjects.

---

<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:** [July 30, 2014, 9:06pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/5 "2014-07-30T21:06:01Z")

</div>

Ok converting to anwser then 🙂 ConstructObject is equivlent of SpawnActor, i find it out by lurking in engine source code so it ok to use it

---

<div class="post-metadata">

**Author:** ![lagrange](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@lagrange](https://forums.unrealengine.com/u/lagrange)\
**Post date:** [September 13, 2015, 2:44pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/6 "2015-09-13T14:44:35Z")

</div>

I see now that ConstructObject is being deprecated in v4.9. What is the correct method then, when ConstructObject is not available anymore?

---

<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:** [September 13, 2015, 3:39pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/7 "2015-09-13T15:39:03Z")

</div>

NewObject ;] now it works ok

---

<div class="post-metadata">

**Author:** ![gamescodedogs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamescodedogs](https://forums.unrealengine.com/u/gamescodedogs)\
**Post date:** [January 15, 2016, 2:27pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/8 "2016-01-15T14:27:51Z")

</div>

Is NewObject still fine? In 4.10.1 i found that ConstructObject is ok, but NewObject is still always creates objects with basic type ignoring TSubclassOf\<\> argument.

---

<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:** [January 17, 2016, 4:59am UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/9 "2016-01-17T04:59:58Z")

</div>

What do you mean by “basic type”?

---

<div class="post-metadata">

**Author:** ![gamescodedogs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamescodedogs](https://forums.unrealengine.com/u/gamescodedogs)\
**Post date:** [January 17, 2016, 8:33am UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/10 "2016-01-17T08:33:03Z")

</div>

I mean that (according to Lordink code) basic type is UTalent and we are trying to create some object of derived class (BP\_Talent for example). So variable TalentClass is TSubclassOf and it’s value is BP\_Talent. After calling NewObject(TalentClass) instance of UTalent will be created, not BP\_Talent.

---

<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:** [January 17, 2016, 4:13pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/11 "2016-01-17T16:13:10Z")

</div>

You calling it like this?

```
NewObject<UTalent>(SomeBlueprintClassVarableYouUse);

```

Also one note TSubclassOf is UClass\* template type, it only limits selection of classes in editor to specific relation

---

<div class="post-metadata">

**Author:** ![gamescodedogs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamescodedogs](https://forums.unrealengine.com/u/gamescodedogs)\
**Post date:** [January 17, 2016, 4:16pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/12 "2016-01-17T16:16:05Z")

</div>

Yep, i’m calling it like this. Thanks, understand UClass\* limitations

---

<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:** [January 17, 2016, 4:34pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/13 "2016-01-17T16:34:57Z")

</div>

Ah i forgot, first argument of NewObject is InParent so you need to call it like this

```
NewObject<UTalent>(this,SomeBlueprintClassVarableYouUse);

```

“this” will become owner of object, it should not have much effect on it i think so you can place whatever you like on it, you might try placing “nullptr” here if you want. I can’t find NewObject in API refrence to show you that, but it should work

---

<div class="post-metadata">

**Author:** ![gamescodedogs](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@gamescodedogs](https://forums.unrealengine.com/u/gamescodedogs)\
**Post date:** [January 17, 2016, 4:37pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/14 "2016-01-17T16:37:45Z")

</div>

Brilliant, thank you, problem was fixed 🙂

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [January 17, 2016, 4:39pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/15 "2016-01-17T16:39:41Z")

</div>

Since this question was initially posted, ConstructObject has been deprecated and you should now always use NewObject. You need to be careful with the arguments though. The first argument is the object to use as the outer (think of it as the owning object) for the newly created object. If you want to specify a particular class to use, pass that as the second argument.

The overloads are not ideal - UClass is actually a descendant of UObject, so if you pass a UClass\* as the first argument, this is an acceptable outer, and since the rest of the parameters have defaults, it will compile, but it won’t be doing what you intend.

---

<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:** [January 17, 2016, 4:41pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/16 "2016-01-17T16:41:58Z")

</div>

Note that this question is old (1.5y actully) back when everyone was using ConstructObject

---

<div class="post-metadata">

**Author:** ![kamrann](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@kamrann](https://forums.unrealengine.com/u/kamrann)\
**Post date:** [January 17, 2016, 4:50pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/17 "2016-01-17T16:50:10Z")

</div>

True, though it’s worth having it updated if people still find it when searching. Updated my answer to reflect that there was nothing wrong with your original answer.

---

<div class="post-metadata">

**Author:** ![darkgaze](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@darkgaze](https://forums.unrealengine.com/u/darkgaze)\
**Post date:** [August 21, 2017, 9:38am UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/18 "2017-08-21T09:38:55Z")

</div>

Do we have to use RegisterComponent afterwards if we create a component object? And UnregisterComponent?

---

<div class="post-metadata">

**Author:** ![william2013987](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@william2013987](https://forums.unrealengine.com/u/william2013987)\
**Post date:** [October 23, 2022, 6:50pm UTC](https://forums.unrealengine.com/t/properly-using-newobject/289717/19 "2022-10-23T18:50:51Z")

</div>

How I use this to get a member of another class value inside another class ?
