# Is there a way to clone / duplicate an Actor in C++?

**URL:** <https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [November 21, 2014, 12:53pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538 "2014-11-21T12:53:22Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [November 21, 2014, 12:53pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/1 "2014-11-21T12:53:22Z")

</div>

Hello, i’m trying to create a copy of an actor in C++, is that possible without setting all the values manually? Thanks 🙂

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [November 21, 2014, 8:40pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/2 "2014-11-21T20:40:18Z")

</div>

SpawnActor has a parameter named Template. If you pass an actor in that, the newly spawned actor will copy the properties from the Template. See FActorSpawnParameters for documentation.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [November 21, 2014, 9:33pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/3 "2014-11-21T21:33:04Z")

</div>

Thank you for the answer 🙂 Tell me something, does that only copy variables that are set as UPROPERTY?

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [November 21, 2014, 10:07pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/4 "2014-11-21T22:07:30Z")

</div>

Yeah, it can only know about the ones that are UPROPs since those are known via the reflection system

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [November 22, 2014, 1:00pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/5 "2014-11-22T13:00:44Z")

</div>

I apologize for another question, but i’m not able to replicate Cloned items, they only show in the server, could it be that he copies the same netguid or something like that? Here is how i’m cloning:

```
class AItem * AItem::Clone()
{
	FActorSpawnParameters Parameters;

	Parameters.Template = this;

	class AItem * Item = GetWorld()->SpawnActor<class AItem>(GetClass(), Parameters);

	Item->SetOwner(GetOwner());

	return Item;
}

```

If i comment Parameters.Template = this; it replicates well.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [November 26, 2014, 3:09pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/6 "2014-11-26T15:09:26Z")

</div>

Any suggestions? 🙂

---

<div class="post-metadata">

**Author:** ![joeGraf](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@joeGraf](https://forums.unrealengine.com/u/joeGraf)\
**Post date:** [November 26, 2014, 5:56pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/7 "2014-11-26T17:56:21Z")

</div>

That sounds like a bug. I’ll get that filed

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [November 26, 2014, 8:42pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/8 "2014-11-26T20:42:03Z")

</div>

Thank you, how can i keep track of the progress of the fix?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_53648559](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_53648559](https://forums.unrealengine.com/u/anonymous_user_53648559)\
**Post date:** [December 1, 2014, 9:00pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/9 "2014-12-01T21:00:48Z")

</div>

If the original actor is replicating, it may be an issue of the new actor not getting put on the replication list inside SpawnActor.

You can try two fixes.

Add this to end of UWorld::SpawnActor:

```
if (Actor->RemoteRole != ROLE_None)
{
	AddNetworkActor(this);
}

```

Or after your SpawnActor call, call SetReplicates with false and then true (more of a temp fix).

We can look into adding the first (more long term fix) if this is your issue. We’re definitely interested if the first option fixes your issue (as this will let us know if we have an internal issue, please do let us know!)

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 1, 2014, 9:26pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/10 "2014-12-01T21:26:47Z")

</div>

Thank you for the follow up, i will try it 🙂

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [December 11, 2014, 1:45pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/11 "2014-12-11T13:45:30Z")

</div>

Sorry for the delay, i was only able to test this now. I don’t know if it’s because i updated to 4.6, but doing the previous code now crashes when initializing the skeletal mesh on:

```
void UActorComponent::InitializeComponent()
{
	check(bRegistered);
	check(!bHasBeenInitialized); // Crashes here
	bHasBeenInitialized = true;
}
```

---

<div class="post-metadata">

**Author:** ![CodeSpartan](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/codespartan/32/1194561_2.png) [@CodeSpartan](https://forums.unrealengine.com/u/CodeSpartan)\
**Post date:** [February 8, 2015, 10:36am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/12 "2015-02-08T10:36:18Z")

</div>

Also interested in this, I’ve made a custom BP node to clone actors but it gives me the same bHasBeenInitialized error.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [March 15, 2015, 1:53pm UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/13 "2015-03-15T13:53:54Z")

</div>

Any news regarding this issue? Thank you 🙂

---

<div class="post-metadata">

**Author:** ![anon67241753](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anon67241753](https://forums.unrealengine.com/u/anon67241753)\
**Post date:** [September 21, 2015, 8:25am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/14 "2015-09-21T08:25:51Z")

</div>

Has anyone figured out a workaround for this? Thanks!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_d0691da8](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_d0691da8](https://forums.unrealengine.com/u/anonymous_user_d0691da8)\
**Post date:** [October 9, 2015, 9:44am UTC](https://forums.unrealengine.com/t/is-there-a-way-to-clone-duplicate-an-actor-in-c/299538/15 "2015-10-09T09:44:59Z")

</div>

Anyone? does this mean that as of now it’s simply not possible to duplicate an aactor using C++?
