# Attaching one component to another crash: 'template mismatch during attachment'

**URL:** <https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [September 19, 2014, 3:25am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645 "2014-09-19T03:25:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 3:25am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/1 "2014-09-19T03:25:02Z")

</div>

Hey guys,

So I’ve extended APlayerStart with my own, AShipStart, from which I inherit to create the blueprint BP\_ShipStart.

I’m adding a UBoxComponent to it, which I’m using as a sort of spawn zone that must be clear of players before it’s considered valid/usable.

.h:

```auto

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Components)
TSubobjectPtr<UBoxComponent> SpawnBoxComponent;

```

.cpp

```auto

AShipStart::AShipStart(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	SpawnBoxComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, "Spawn Box");
	SpawnBoxComponent->SetWorldScale3D(FVector(200, 200, 200));
	SpawnBoxComponent->AttachTo(RootComponent);
}

```

After this, when I open the editor I get a message about a ‘bad component’ with reference to the above UBoxComponent.

> [@](#):
>
> Error Failed import: BoxComponent /Game/Blueprints/Core/BP\_ShipStart.Default\_\_BP\_ShipStart\_C:Spawn Box in /Game/Maps/Default\_Map

It also often crashes when hitting ‘Play’ in the editor.

> [@](#):
>
> Ensure condition failed: false [File:F:\P4\_BH\_Home\UnrealEngine\Engine\Source\Runtime\Engine\Private\SceneComponent.cpp] [Line: 744]  
> Template Mismatch during attachment. Attaching instanced component to template component. Parent ‘CollisionCapsule’ Self ‘Spawn Box’  
> UE4Editor.exe has triggered a breakpoint.

Any ideas? Never encountered this before.

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 4:37am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/2 "2014-09-19T04:37:41Z")

</div>

RootComponent = SpawnBoxComponent;

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 4:46am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/3 "2014-09-19T04:46:23Z")

</div>

> [@newbprofi;146348](#):
>
> RootComponent = SpawnBoxComponent;

Why would I want to replace the pre-existing capsule root component?

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 5:02am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/4 "2014-09-19T05:02:38Z")

</div>

> [@;146362](#):
>
> Why would I want to replace the pre-existing capsule root component?

You didnt give any information about root component.

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 5:04am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/5 "2014-09-19T05:04:28Z")

</div>

> [@newbprofi;146379](#):
>
> You didnt give any information about root component.

APlayerStart comes with a root capsule component.

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 5:11am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/6 "2014-09-19T05:11:50Z")

</div>

> [@;146382](#):
>
> APlayerStart comes with a root capsule component.

Error says: root component is a template component, obviously you need both components to be templates or instances. You need to show information about how RootComponent is initialized and how Capsule Component is created.

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 5:12am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/7 "2014-09-19T05:12:34Z")

</div>

> [@newbprofi;146390](#):
>
> Error says: root component is a template component, obviously you need both components to be templates or instances.

What does that mean?

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 5:16am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/8 "2014-09-19T05:16:24Z")

</div>

> [@;146391](#):
>
> What does that mean?

Have no idea what is template component ;d Perhaps i could say smth if you show how you initialize RootComponent and create Capsule Component.

UPD: wait, i found APlayerStart in ue4.

UPD2: well, i see nothing strange in RootComponent. May be you should try to remove VisibleDefaultsOnly specifier for your component?

PS: i am learning Components right now, thats why i am interested in your question too.

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 5:22am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/9 "2014-09-19T05:22:23Z")

</div>

> [@newbprofi;146396](#):
>
> Have no idea what is template component ;d Perhaps i could say smth if you show how you initialize RootComponent and create Capsule Component.
> 
> UPD: wait, i found APlayerStart in ue4.

Aye, but the capsule component is initialized in ANavigationObjectBase:

```auto

CapsuleComponent = PCIP.CreateDefaultSubobject<UCapsuleComponent>(this, TEXT("CollisionCapsule"));
CapsuleComponent->ShapeColor = FColor(255, 138, 5, 255);
CapsuleComponent->bDrawOnlyIfSelected = true;
CapsuleComponent->InitCapsuleSize(50.0f, 50.0f);
CapsuleComponent->BodyInstance.bEnableCollision_DEPRECATED = false;
CapsuleComponent->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
CapsuleComponent->bShouldCollideWhenPlacing = true;
CapsuleComponent->bShouldUpdatePhysicsVolume = true;
CapsuleComponent->Mobility = EComponentMobility::Static;
RootComponent = CapsuleComponent;
bCollideWhenPlacing = true;

```

I don’t see what makes it a ‘template’ component.

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 5:24am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/10 "2014-09-19T05:24:59Z")

</div>

> [@;146408](#):
>
> Aye, but the capsule component is initialized in ANavigationObjectBase:
> 
> ```auto
> 
> CapsuleComponent = PCIP.CreateDefaultSubobject<UCapsuleComponent>(this, TEXT("CollisionCapsule"));
> CapsuleComponent->ShapeColor = FColor(255, 138, 5, 255);
> CapsuleComponent->bDrawOnlyIfSelected = true;
> CapsuleComponent->InitCapsuleSize(50.0f, 50.0f);
> CapsuleComponent->BodyInstance.bEnableCollision_DEPRECATED = false;
> CapsuleComponent->SetCollisionProfileName(UCollisionProfile::NoCollision_ProfileName);
> CapsuleComponent->bShouldCollideWhenPlacing = true;
> CapsuleComponent->bShouldUpdatePhysicsVolume = true;
> CapsuleComponent->Mobility = EComponentMobility::Static;
> RootComponent = CapsuleComponent;
> bCollideWhenPlacing = true;
> 
> ```
> 
> I don’t see what makes it a ‘template’ component.

Y me too, try to change your component’s specifiers, for example remove VisibleDefaultsOnly.  
As i understand template component is a component which has flags RF\_ArchetypeObject|RF\_ClassDefaultObject.

UPD: i’ve tested UPROPERTY specifiers, they doesnt affect. Well, i suppose the problem is somewhere in blueprint, may be you instantiate SpawnBoxComponent somewhere or smth like that. Because i’ve tested to attach the same box to the same capsule and everything is fine. I am using UE4.4.1.

UPD2: if i create SpawnBoxComponent or CapsuleComponent without using any blueprints it is still IsTemplate()==false. So, afterall, i think the problem is about how UE4 engine using ANavigationObjectBase inside engine and why Capsule component is becoming Template for this object. Component is not supposed to be Template by default i think.

**The question is** what is Template Componnt and how it did become a Template.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_6334e343](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_6334e343](https://forums.unrealengine.com/u/anonymous_user_6334e343)\
**Post date:** [September 19, 2014, 6:54am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/11 "2014-09-19T06:54:33Z")

</div>

Hey try.

```auto

UPROPERTY(VisibleAnywhere, Category = "MyComponents")
TSubobjectPtr<UBoxComponent> SpawnBoxComponent;

```

```auto

AShipStart::AShipStart(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	SpawnBoxComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Spawn Box"));
        if (SpawnBoxComponent )
        {
	      SpawnBoxComponent->AttachParent = RootComponent;
	      SpawnBoxComponent->SetWorldScale3D(FVector(200, 200, 200));
        }
}

```

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 7:11am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/12 "2014-09-19T07:11:46Z")

</div>

> [@;146517](#):
>
> Hey try.
> 
> ```auto
> 
> UPROPERTY(VisibleAnywhere, Category = "MyComponents")
> TSubobjectPtr<UBoxComponent> SpawnBoxComponent;
> 
> ```
> 
> ```auto
> 
> AShipStart::AShipStart(const class FPostConstructInitializeProperties& PCIP)
> : Super(PCIP)
> {
> SpawnBoxComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Spawn Box"));
> if (SpawnBoxComponent )
> {
> SpawnBoxComponent->AttachParent = RootComponent;
> SpawnBoxComponent->SetWorldScale3D(FVector(200, 200, 200));
> }
> }
> 
> ```

That definitly should work. The question is, why UE4 engine supports so strange methods of attaching, if they meaning absolutely the same, but behaves differently…

I made some observations of UE4 code, and i think AttachParent is used mostly inside constructors, while AttachTo is not used inside constructors.

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 7:30am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/13 "2014-09-19T07:30:10Z")

</div>

> [@;146517](#):
>
> Hey try.
> 
> ```auto
> 
> UPROPERTY(VisibleAnywhere, Category = "MyComponents")
> TSubobjectPtr<UBoxComponent> SpawnBoxComponent;
> 
> ```
> 
> ```auto
> 
> AShipStart::AShipStart(const class FPostConstructInitializeProperties& PCIP)
> : Super(PCIP)
> {
> SpawnBoxComponent = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Spawn Box"));
> if (SpawnBoxComponent )
> {
> SpawnBoxComponent->AttachParent = RootComponent;
> SpawnBoxComponent->SetWorldScale3D(FVector(200, 200, 200));
> }
> }
> 
> ```

Same error. When I open the editor/level:

> [@](#):
>
> Error Failed import: BoxComponent /Game/Blueprints/Core/BP\_ShipStart.Default\_\_BP\_ShipStart\_C:Spawn Box in /Game/Maps/Default\_Map

When I hit play, and crash:

> [@](#):
>
> Ensure condition failed: false [File:F:\P4\_BH\_Home\UnrealEngine\Engine\Source\Runtime\Engine\Private\SceneComponent.cpp] [Line: 744]  
> Template Mismatch during attachment. Attaching instanced component to template component. Parent ‘CollisionCapsule’ Self ‘Spawn Box’  
> UE4Editor.exe has triggered a breakpoint.

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 7:41am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/14 "2014-09-19T07:41:59Z")

</div>

> [@;146563](#):
>
> Same error. When I open the editor/level:
> 
> When I hit play, and crash:

Line:744? What is your UE version?

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 19, 2014, 7:46am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/15 "2014-09-19T07:46:37Z")

</div>

> [@newbprofi;146584](#):
>
> Line:744? What is your UE version?

Preview build 2289630.

---

<div class="post-metadata">

**Author:** ![newbprofi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@newbprofi](https://forums.unrealengine.com/u/newbprofi)\
**Post date:** [September 19, 2014, 8:02am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/16 "2014-09-19T08:02:12Z")

</div>

AttachTo is auto-called inside OnRegister for AttachParent variable, so… yes, you still have the same error.  
Try to use previous stable version.

\*\*The question still is \*\*how Component did become a Template.

Ok, im out. This is definitely the problem of UE4, not of your component.

---

<div class="post-metadata">

**Author:** ![Marc\_Audy](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/marc_audy/32/710746_2.png) [@Marc\_Audy](https://forums.unrealengine.com/u/Marc_Audy)\
**Post date:** [September 19, 2014, 3:02pm UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/17 "2014-09-19T15:02:34Z")

</div>

Couple of shot gun answers to various things in the thread:

As was mentioned AttachParent should be used when setting up your components in the constructor because it will do the AttachTo and all the associated actions when the components get registered. Doing AttachTo in the constructor will generally not get you what you want.

Template component simply means that it is a component that belongs to the Class Default Object, which is the prototype/template object from which other instanced objects get their properties initialized from.

The ensure message means that when the attachment is being executed your SpawnBox component is trying to attach itself to the component in the CDO, not its own instanced version.

I tried to reproduce this ensure by creating a new subclass of ANavigationObjectBase and just putting in the subobject pointer as in 's post, but I couldn’t reproduce it. It probably shouldn’t cause an issue, but try taking the space out of the name of the component?

If you’re able to isolate the problem down to a simple repro in a new project, please do post on answerhub and attach the project.

---

<div class="post-metadata">

**Author:** ![HateDread](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@HateDread](https://forums.unrealengine.com/u/HateDread)\
**Post date:** [September 20, 2014, 6:29am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/18 "2014-09-20T06:29:29Z")

</div>

> [@;146869](#):
>
> Couple of shot gun answers to various things in the thread:
> 
> As was mentioned AttachParent should be used when setting up your components in the constructor because it will do the AttachTo and all the associated actions when the components get registered. Doing AttachTo in the constructor will generally not get you what you want.
> 
> Template component simply means that it is a component that belongs to the Class Default Object, which is the prototype/template object from which other instanced objects get their properties initialized from.
> 
> The ensure message means that when the attachment is being executed your SpawnBox component is trying to attach itself to the component in the CDO, not its own instanced version.
> 
> I tried to reproduce this ensure by creating a new subclass of ANavigationObjectBase and just putting in the subobject pointer as in 's post, but I couldn’t reproduce it. It probably shouldn’t cause an issue, but try taking the space out of the name of the component?
> 
> If you’re able to isolate the problem down to a simple repro in a new project, please do post on answerhub and attach the project.

Hi Marc,

I’ve managed to reproduce this issue with Preview Build 2289630: [Adding UBoxComponent to a custom PlayerStart class crashes gameplay - Programming & Scripting - Epic Developer Community Forums](https://answers.unrealengine.com/questions/101043/preview-build-2289630-adding-uboxcomponent-to-a-cu.html)

Turns out it only happens when you place the custom PlayerStart in the world, then copy-paste it to make several instances. This process is fine with normal PlayerStart objects, but when you try to add your own components like I have above, and then copy-paste that custom PlayerStart, it crashes when PIE (haven’t tested standalone).

---

<div class="post-metadata">

**Author:** ![IEliot](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/ieliot/32/1117433_2.png) [@IEliot](https://forums.unrealengine.com/u/IEliot)\
**Post date:** [July 11, 2018, 9:32am UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/19 "2018-07-11T09:32:16Z")

</div>

Hello everyone!  
Who can solve my problem?

When i attach a actor to my character mesh(C++), error " template mismatch during attachment "

but it is correct in Blueprint  
what’s wrong?

---

<div class="post-metadata">

**Author:** ![WillOrmerodCA](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@WillOrmerodCA](https://forums.unrealengine.com/u/WillOrmerodCA)\
**Post date:** [December 15, 2020, 2:35pm UTC](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/20 "2020-12-15T14:35:47Z")

</div>

This is still present in unreal (4.24), so going to post this for future reference - compile and resaving the blueprint that the actor was generated from will fix this error. Would be great if unreal could warn about this kind of issue in a more understandable way.

[Next page](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645.md?page=2)
