# Can I dynamic CreateDefaultSubobject but not just in init function

**URL:** <https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 25, 2014, 6:14am UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549 "2014-09-25T06:14:34Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ryuikuya](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ryuikuya](https://forums.unrealengine.com/u/ryuikuya)\
**Post date:** [September 25, 2014, 6:14am UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/1 "2014-09-25T06:14:34Z")

</div>

I want to dynamic create following object:

```
TSubobjectPtr<USceneComponent> EmptySceneCom = aPCIP->CreateDefaultSubobject<USceneComponent>(this, newName);

```

But if I did not create the object in init function like following:

```
APositionIndicator::APositionIndicator(const FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{

}

```

It will be crashed. does anyway to create the object in other’s function?

---

<div class="post-metadata">

**Author:** ![Heroico](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Heroico](https://forums.unrealengine.com/u/Heroico)\
**Post date:** [March 26, 2015, 2:54pm UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/2 "2015-03-26T14:54:04Z")

</div>

I would recommend you to take a look at this:

[Object Instance Creation](https://docs.unrealengine.com/latest/INT/Programming/UnrealArchitecture/Objects/Creation/index.html)

The thing is that the “DefaultSubobject” is a method with some extra functionality related to the Editor property setup functionality (at least that’s what I use it for). That is: use that method if you want to get the settings you entered at the editor entity inspector.

I usually create my ordinary objects dynamically with something like this:

```
USceneComponent *Component = ConstructObject<USceneComponent>(USceneComponent::StaticClass(), this, NewName);

```

---

<div class="post-metadata">

**Author:** ![Heroico](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Heroico](https://forums.unrealengine.com/u/Heroico)\
**Post date:** [June 13, 2015, 8:32pm UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/3 "2015-06-13T20:32:12Z")

</div>

Update: in UE 4.8,

**ConstructObject** has been deprecated in favor of **NewObject**

---

<div class="post-metadata">

**Author:** ![SDuval](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SDuval](https://forums.unrealengine.com/u/SDuval)\
**Post date:** [September 30, 2015, 9:07pm UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/4 "2015-09-30T21:07:40Z")

</div>

CreateDefaultSubobject can only be called within the UObject constructor.

---

<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 19, 2017, 11:48am UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/5 "2017-08-19T11:48:00Z")

</div>

- Never use CreateDefaultSubobject outside a constructor. It will crash the editor (4.17…)
- Don’t use: ConstructObject ← Deprecated from 4.9
- Use NewObject. parent can be “this” if you are creating the object underneath this one.

**How to use** :

```
NewObject < classToReturn > (parent, ComponentClassToSpawn*)

```

**Example:**

```
USceneComponent* var = NewObject<USceneComponent>(this,USphereComponent::StaticClass());

```

Note USceneC is parent type of USphereC.

**Other answers here:**

> **[Properly using NewObject](https://forums.unrealengine.com/questions/76747/properly-using-newobject.html)**
>
> Hi guys, I have a UObject-inheriting class here: 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...

**NewObject docs:**

> **[NewObject](https://docs.unrealengine.com/5.1/en-US/API/Runtime/CoreUObject/UObject/NewObject/)**
>
> Overload list

**About objects creation:**

> **[UObject Instance Creation](https://docs.unrealengine.com/5.1/en-US/creating-objects-in-unreal-engine/)**
>
> Methods of creating new instances of Objects in gameplay code.

---

<div class="post-metadata">

**Author:** ![cpu](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cpu](https://forums.unrealengine.com/u/cpu)\
**Post date:** [January 9, 2025, 8:24pm UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/6 "2025-01-09T20:24:17Z")

</div>

Don’t forget to do  
var-\>RegisterObject();  
after NewObject  
I just lost a hour or 2 because my skeletal mesh wasn’t visible, nor ticking, but the component (gun) worked, and correctly shooted on click  
I couldn’t understand why .\_.

---

<div class="post-metadata">

**Author:** ![RadicalGratitud](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RadicalGratitud](https://forums.unrealengine.com/u/RadicalGratitud)\
**Post date:** [April 28, 2025, 6:20am UTC](https://forums.unrealengine.com/t/can-i-dynamic-createdefaultsubobject-but-not-just-in-init-function/294549/7 "2025-04-28T06:20:22Z")

</div>

Using Unreal 5.5, used RegisterComponent instead of RegisterObject and just created the actual component instead of casting to parent USceneComponent:

```auto
UInstancedStaticMeshComponent* Ism = NewObject<UInstancedStaticMeshComponent>(this,UInstancedStaticMeshComponent::StaticClass()); // per @darkgaze comment
Ism->RegisterComponent(); // needed so component is visible, per @cpu comment
FString ISMName = FName("ISM_Mesh_").ToString().Append(FString::FromInt(1));
Ism->Rename(*ISMName);
// IsmParent is a USceneComponent parent that has Ism child
Ism->AttachToComponent(IsmParent, FAttachmentTransformRules::KeepRelativeTransform);

```
