# Component created with NewObject is invisible

**URL:** <https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937>\
**Category:** C++\
**Tags:** newobject, unreal-engine, CPP, question\
**Created:** [November 18, 2017, 6:28am UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937 "2017-11-18T06:28:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1c4cdb3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1c4cdb3c](https://forums.unrealengine.com/u/anonymous_user_1c4cdb3c)\
**Post date:** [November 18, 2017, 6:28am UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/1 "2017-11-18T06:28:13Z")

</div>

I was creating a sub-object inside my actor’s constructor the usual way:

```
AMyActor::AMyActor(const FObjectInitializer &init) : Super(init)
{
    text_render = CreateDefaultSubobject<UTextRenderComponent>(TEXT("info_text"));
}

```

Worked fine. Then I needed to move this creation into a member object of the actor and do this creation outside the constructor. The recommended approach was to use NewObject:

```
SomeMemberOfMyActor::init()
{
    text_render = NewObject<UTextRenderComponent>(m_owner, TEXT("info_text"));
}

```

This compiles and runs and creates the component, but it’s invisible. It seems like that second parameter is wrong – it should be a “UClass” instead of a text string. But what “UClass” would I use for a text render component?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1c4cdb3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1c4cdb3c](https://forums.unrealengine.com/u/anonymous_user_1c4cdb3c)\
**Post date:** [November 18, 2017, 6:39am UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/2 "2017-11-18T06:39:33Z")

</div>

Followup: I tried passing UTextRenderComponent::StaticClass() as the second argument, which also compiles and runs, but the component is still invisible.

In both cases, I can see all the properties of the UTextRenderComponent in the editor, under “Details.” All of the object’s properties look correct. And, under “Rendering,” the “Visible” checkbox is checked.

---

<div class="post-metadata">

**Author:** ![Zedokus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Zedokus](https://forums.unrealengine.com/u/Zedokus)\
**Post date:** [November 18, 2017, 6:59am UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/3 "2017-11-18T06:59:51Z")

</div>

maybe it’s visible, but spawned in the origin of the world? try text\_render-\>AttachToComponent(…);

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_1c4cdb3c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1c4cdb3c](https://forums.unrealengine.com/u/anonymous_user_1c4cdb3c)\
**Post date:** [November 18, 2017, 2:59pm UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/4 "2017-11-18T14:59:59Z")

</div>

The attachment and transform are the same in both cases.  
Something interesting, when I double-click the object in the hierarchy, it doesn’t focus the camera on it, like it can’t find it.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d4aadacc1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d4aadacc1](https://forums.unrealengine.com/u/anonymous_user_d4aadacc1)\
**Post date:** [July 19, 2019, 5:27pm UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/5 "2019-07-19T17:27:30Z")

</div>

Got exactly same problem, solved with RegisterComponent:

```
UParticleSystemComponent* psc = NewObject<UParticleSystemComponent(OwnerActor);
if (psc) {
	psc->SetTemplate(Particle);
	psc->RegisterComponent();
}

```

---

<div class="post-metadata">

**Author:** ![CresCoJeff](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@CresCoJeff](https://forums.unrealengine.com/u/CresCoJeff)\
**Post date:** [March 15, 2021, 2:50am UTC](https://forums.unrealengine.com/t/component-created-with-newobject-is-invisible/409937/6 "2021-03-15T02:50:17Z")

</div>

I ran into a similar issue that was solved by [this answer](https://answers.unrealengine.com/questions/675392/component-made-with-newobject-cannot-be-moved.html) – turns out it was a weird matter of CDOs. The UStaticMeshComponent (and/or the UStaticMesh) created in the ctor of the component I was trying to create/add at runtime only worked for one instance, presumably because the CDO paradigm has the Component constructor only ever called once; all future instances were present but invisible. I moved the UStaticMeshComponent and other init things from the ctor to BeginPlay() and everything worked nicely!

I don’t understand why the subsequent instances couldn’t re-use the mesh data, though. Even assuming each instance was pairing the same mesh with its own unique transform should have meant that only the latest instance was visible, rather than only the first. I’ve asked my own [question](https://answers.unrealengine.com/questions/1017893/uscenecomponents-created-at-runtime-are-invisible.html) about that!
