# How to instantiate using New Object?

**URL:** <https://forums.unrealengine.com/t/how-to-instantiate-using-new-object/384070>\
**Category:** Community & Industry Discussion\
**Tags:** library, newobject, actorcomponent, unreal-engine, question\
**Created:** [February 6, 2017, 12:54pm UTC](https://forums.unrealengine.com/t/how-to-instantiate-using-new-object/384070 "2017-02-06T12:54:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_1ed1c3df](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_1ed1c3df](https://forums.unrealengine.com/u/anonymous_user_1ed1c3df)\
**Post date:** [February 6, 2017, 12:54pm UTC](https://forums.unrealengine.com/t/how-to-instantiate-using-new-object/384070/1 "2017-02-06T12:54:53Z")

</div>

This subject seems to have gotten a little murky since Construct Object was depreciated.

What is the correct way to use New Object to spawn a new instance of a UClass? I’m trying to build a custom factory for dynamically creating actor components at run time.

```
Library.h

UFUNCTION(BlueprintCallable, Category="WhyUNoSpawnOutsideActor")
	static void SpawnActorComponentFromClass(UClass *actorComponent, class AActor *Owner);

Library.cpp

void UApolloLibrary::SpawnActorComponentFromClass(UClass *actorComponent, class AActor *Owner)
{
   NewObject(Owner, actorComponent);
   //Owner->AddOwnedComponent(SpawnedComponent);
}

```

---

<div class="post-metadata">

**Author:** ![Bionic\_Ape](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bionic_ape/32/1090124_2.png) [@Bionic\_Ape](https://forums.unrealengine.com/u/Bionic_Ape)\
**Post date:** [February 6, 2017, 2:22pm UTC](https://forums.unrealengine.com/t/how-to-instantiate-using-new-object/384070/2 "2017-02-06T14:22:52Z")

</div>

try this:  
.h

```
UFUNCTION(BlueprintCallable, Category = "WhyUNoSpawnOutsideActor")
	static void SpawnActorComponentFromClass(TSubclassOf<class UActorComponent> ComponentClass, AActor* Owner);

```

.cpp  
{

```
UWorld* World = Owner->GetWorld();

UActorComponent* NewComp = NewObject<UActorComponent>(Owner, ComponentClass);
NewComp->RegisterComponentWithWorld(World);

```

}

I’m not sure that you need to register it, please try and let me know.
