# Spawning an Actor with a Template Actor set in the FActorSpawnParameters prevents the spawned Actor from replicating

**URL:** <https://forums.unrealengine.com/t/spawning-an-actor-with-a-template-actor-set-in-the-factorspawnparameters-prevents-the-spawned-actor-from-replicating/479356>\
**Category:** Community & Industry Discussion\
**Tags:** spawn, copy, Replication, unreal-engine, template, question\
**Created:** [February 24, 2021, 6:51pm UTC](https://forums.unrealengine.com/t/spawning-an-actor-with-a-template-actor-set-in-the-factorspawnparameters-prevents-the-spawned-actor-from-replicating/479356 "2021-02-24T18:51:40Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Infernobirb](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Infernobirb](https://forums.unrealengine.com/u/Infernobirb)\
**Post date:** [February 24, 2021, 6:51pm UTC](https://forums.unrealengine.com/t/spawning-an-actor-with-a-template-actor-set-in-the-factorspawnparameters-prevents-the-spawned-actor-from-replicating/479356/1 "2021-02-24T18:51:40Z")

</div>

I originally stumbled across this Issue while trying to get the ChildActorComponent to replicate the Actor properly. Spoiler: The ChildActorComponent will not replicate the the Child Actor because of this issue. Two methods for reproducing:

Method 1, using a ChildActorComponent

1. Create a new Blueprint Actor, BP\_Child (give it a cube so you can see it)
2. Create a new Blueprint Actor, BP\_Parent and give it a ChildActorComponent
3. Set the ChildActorClass of the ChildActorComponent to BP\_Child
4. Set the Replicates flag on either the BP\_Child Blueprint, or the details panel of theChildActorComponent to “true”
5. Set NetMode in the Play dropdown to “Play as Listen Server”
6. Set “Num Players” to 2
7. Start with “Standalone Game” option
8. Observer that the BP\_Child actor is not present on the Client window

Method 2, using a custom SpawnActorFromTemplate() UFUNCTION

1. Add class based on BlueprintFunctionLibrary (MyFunctionLib)
2. Add the following to MyFunctionLib.h

```
UFUNCTION(BlueprintCallable, Category = "Actor")
static AActor* SpawnActorFromTemplate(AActor* Template, FTransform Transform)
{
	AActor* Result;
	FActorSpawnParameters Params;
	Params.Template = Template;
	Result = Template->GetWorld()->SpawnActor(Template->GetClass(), &Transform, Params);
	return Result;
}

```

1. Create an actor Blueprint BP\_TemplateActor (give it a cube so you can see it)
2. Check the “Replicates” box of the actor
3. Call the SpawnActorFromTemplate function from somewhere (e.g. in the LevelBlueprint of a map)
4. Set “Num Players” to 2
5. Start with “Standalone Game” option
6. Observer that the BP\_TemplateActor actor is not present on the Client window

The oldest (and only) record of this bug that I was able to find is [this](https://answers.unrealengine.com/questions/136562/is-there-a-way-to-clone-duplicate-an-actor-in-c.html) thread from 2014. It’s honestly kind of baffling that this is still an issue, since this seems like a really bad bug that would prevent any kind of reasonable use of the ChildActorComponent.

**WORKAROUND:**

If you have this problem, there are two solutions I have found.  
Solution method 1:

1. Create a new C++ child class of ChildActorComponent

```

UCLASS()
public UMyChildActorComponent : public UChildActorComponent

```

1. Override the “CreateChildActor()” method like this

```

void UBGChildActorComponent::CreateChildActor()
{
	Super::CreateChildActor();
	if (GetChildActor() && GetChildActor()->GetIsReplicated())
	{
		GetWorld()->AddNetworkActor(GetChildActor());
	}
}

```

Note that the ChildActor property of the ChildActorComponent might still not be valid in the BeginPlay event on the Client

Solution method 2:

1. Rewrite your “SpawnActorFromTemplate()” method like this

```

UFUNCTION(BlueprintCallable, Category = "Actor")
static AActor* SpawnActorFromTemplate(AActor* Template, FTransform Transform)
{
	AActor* Result;
	FActorSpawnParameters Params;
	Params.Template = Template;
	Result = Template->GetWorld()->SpawnActor(Template->GetClass(), &Transform, Params);
	if (Result->GetIsReplicated())
	{
		Template->GetWorld()->AddNetworkActor( Result );
	}
	return Result;
}

```

I hope this helps somebody out, since I banged my head against this for a while.
