# 'Template Mismatch during attachment' when parenting a BP with my class

**URL:** <https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [March 26, 2015, 5:13am UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646 "2015-03-26T05:13:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![RyanTylerRae](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanTylerRae](https://forums.unrealengine.com/u/RyanTylerRae)\
**Post date:** [March 26, 2015, 5:13am UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/1 "2015-03-26T05:13:08Z")

</div>

Hello,

I have a class that I can drag into a map and use just fine. However if I parent a Blueprint with this class and drag it into a map, I get the following crash. I did some delving and found that at the time of the crash, my capsule component has a RF\_Transactional flag set which might be causing problems but I’m not sure what it means. I want to be able to create a blueprint of this class for editing variables and functionality in Blueprint, but is this not the way I should go about things? Thanks, more specific details follow below:

The callstack is this:

```
 	KernelBase.dll!000007fefd613ca2()	Unknown
>	UE4Editor-Engine.dll!USceneComponent::AttachTo(USceneComponent * Parent, FName InSocketName, EAttachLocation::Type AttachType, bool bWeldSimulatedBodies) Line 914	C++
 	UE4Editor-Engine.dll!USceneComponent::OnRegister() Line 130	C++
 	UE4Editor-Engine.dll!UPrimitiveComponent::OnRegister() Line 305	C++
 	UE4Editor-Engine.dll!UActorComponent::ExecuteRegisterEvents() Line 945	C++
 	UE4Editor-Engine.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld) Line 749	C++
 	UE4Editor-Engine.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister) Line 3271	C++
 	UE4Editor-Engine.dll!ULevel::IncrementalUpdateComponents(int NumComponentsToUpdate, bool bRerunConstructionScripts) Line 720	C++
 	UE4Editor-Engine.dll!UWorld::UpdateWorldComponents(bool bRerunConstructionScripts, bool bCurrentLevelOnly) Line 1205	C++
 	UE4Editor-Engine.dll!UWorld::InitializeActorsForPlay(const FURL & InURL, bool bResetTime) Line 2831	C++
 	UE4Editor-Engine.dll!UGameInstance::StartPIEGameInstance(ULocalPlayer * LocalPlayer, bool bInSimulateInEditor, bool bAnyBlueprintErrors, bool bStartInSpectatorMode) Line 195	C++
 	UE4Editor-UnrealEd.dll!UEditorEngine::CreatePIEGameInstance(int PIEInstance, bool bInSimulateInEditor, bool bAnyBlueprintErrors, bool bStartInSpectatorMode, bool bRunAsDedicated, float PIEStartTime) Line 2861	C++
 	UE4Editor-UnrealEd.dll!UEditorEngine::PlayInEditor(UWorld * InWorld, bool bInSimulateInEditor) Line 2212	C++
 	UE4Editor-UnrealEd.dll!UEditorEngine::StartQueuedPlayMapRequest() Line 974	C++
 	UE4Editor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1226	C++
 	UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 347	C++
 	UE4Editor.exe!FEngineLoop::Tick() Line 2257	C++
 	UE4Editor.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE __* hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 142	C++
 	UE4Editor.exe!WinMain(HINSTANCE __* hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 191	C++
 	[External Code]	

```

The error message I receive is this:

```
Template Mismatch during attachment. Attaching instanced component to template component. Parent 'CapsuleComponent' Self 'PlayerMesh'

```

This is my class cpp file:

```
// Fill out your copyright notice in the Description page of Project Settings.

#include "ColossusProject.h"
#include "OwlPawn.h"

// Sets default values
AOwlPawn::AOwlPawn()
{
 	// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	// attach a capsule component as the root component
	UCapsuleComponent* CapsuleComponent = CreateDefaultSubobject<UCapsuleComponent>(TEXT("CapsuleComponent"));
	RootComponent = CapsuleComponent;
	CapsuleComponent->InitCapsuleSize(25.0f, 25.0f);

	// attach a static mesh so the player has something to see
	UStaticMeshComponent* PlayerMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("PlayerMesh"));
	PlayerMesh->AttachTo(RootComponent);
	static ConstructorHelpers::FObjectFinder<UStaticMesh> SphereVisualAsset(TEXT("/Game/StarterContent/Shapes/Shape_Sphere.Shape_Sphere"));
	if (SphereVisualAsset.Succeeded())
	{
		PlayerMesh->SetStaticMesh(SphereVisualAsset.Object);
		PlayerMesh->SetRelativeLocation(FVector(0.0f, 0.0f, -40.0f));
	}

	// attach a spring arm and a camera for visuals
	USpringArmComponent* SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraSpringArm"));
	SpringArm->AttachTo(RootComponent);
	SpringArm->SetRelativeRotation(FRotator(-15.0f, 0.0f, 0.0f));
	SpringArm->TargetArmLength = 400.0f;

	// attach a camera to the spring arm
	UCameraComponent* Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("PlayerCamera"));
	Camera->AttachTo(SpringArm, USpringArmComponent::SocketName);

	// attach a movement component so we can move
	PawnMovementComponent = CreateDefaultSubobject<UOwlPawnMovementComponent>(TEXT("PlayerMovement"));
	PawnMovementComponent->UpdatedComponent = RootComponent;

	// automatically take control of this pawn
	AutoPossessPlayer = EAutoReceiveInput::Player0;
}

// Called when the game starts or when spawned
void AOwlPawn::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void AOwlPawn::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

// Called to bind functionality to input
void AOwlPawn::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
	Super::SetupPlayerInputComponent(InputComponent);

	// set up keybindings
	InputComponent->BindAxis(TEXT("MoveRight"), this, &AOwlPawn::MoveRight);
	InputComponent->BindAxis(TEXT("MoveForward"), this, &AOwlPawn::MoveForward);
}

// Moves the player to the right
void AOwlPawn::MoveRight(float AxisValue)
{
	if (PawnMovementComponent && AxisValue != 0.0f)
	{
		PawnMovementComponent->AddInputVector(GetActorRightVector() * AxisValue);
	}
}

// Moves the player forward
void AOwlPawn::MoveForward(float AxisValue)
{
	if (PawnMovementComponent && AxisValue != 0.0f)
	{
		PawnMovementComponent->AddInputVector(GetActorForwardVector() * AxisValue);
	}
}
```

---

<div class="post-metadata">

**Author:** ![RyanTylerRae](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@RyanTylerRae](https://forums.unrealengine.com/u/RyanTylerRae)\
**Post date:** [March 27, 2015, 4:45am UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/2 "2015-03-27T04:45:29Z")

</div>

Kept up research, and spawning this class instead through a PlayerStart works fine for those who run into this issue. I’d still like to know why this is an issue though.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_5d61bb2c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_5d61bb2c](https://forums.unrealengine.com/u/anonymous_user_5d61bb2c)\
**Post date:** [April 23, 2015, 2:37am UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/3 "2015-04-23T02:37:38Z")

</div>

I was getting this issue as well. After looked a bit at the generated code and doing some tinkering, I think I found out what was causing this. I think you need to make your CapsuleComponent a UProperty like this:

```
UPROPERTY(Category = Private, VisibleDefaultsOnly)
	class USceneComponent* SceneComponent;

```

If I comment out the UPROPERTY, then I get the same error. So, it seems that if you are attaching a component to something, then that something should be a UPROPERTY.

Let me know if this changes anything. I’m curious to know if this works for other people than me.

---

<div class="post-metadata">

**Author:** ![KeltRivera\_1](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@KeltRivera\_1](https://forums.unrealengine.com/u/KeltRivera_1)\
**Post date:** [April 28, 2015, 4:28pm UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/4 "2015-04-28T16:28:06Z")

</div>

Hi! Looks like I found the issue here. If you use just CreateDefaultSubobject\<\>() while creating your component it causes it to be garbage-collected, so engine just deletes it and you get the crash (I had it myself for my code). Looks like you should use the UPROPERTY() tag before your component declaration, just like BegKev said before (before ALL of the components). With this tag included, your object is now properly initialized and don’t get “garbage-collected”. It worked for me.

I found (more detailed) explanation of it here: (thanks to cmartel)

> **[no clue why a very basic piece of code crashes](https://forums.unrealengine.com/showthread.php?64234-no-clue-why-a-very-basic-piece-of-code-crashes)**
>
> Hello community, I wanted to test something during my current project and started a clean project with a very little, basic code fragment. Unfortunately, as soon as i create a blueprint class from it, place it in an empty level and hit ‘Play’ it...

---

<div class="post-metadata">

**Author:** ![MeloinUnreal](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MeloinUnreal](https://forums.unrealengine.com/u/MeloinUnreal)\
**Post date:** [December 24, 2024, 8:02am UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/5 "2024-12-24T08:02:38Z")

</div>

Pressing Asset Actions → Reload helped me to fix this problem

---

<div class="post-metadata">

**Author:** ![RVillani](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/rvillani/32/1194572_2.png) [@RVillani](https://forums.unrealengine.com/u/RVillani)\
**Post date:** [October 16, 2025, 8:06pm UTC](https://forums.unrealengine.com/t/template-mismatch-during-attachment-when-parenting-a-bp-with-my-class/312646/6 "2025-10-16T20:06:54Z")

</div>

I explain the problem and suggest some solutions [here](https://forums.unrealengine.com/t/problems-spawning-sounds-attatched-to-a-component/2592331/3). Hope this helps others, as I spent days on issues from nested components and decided to figure out what was really going on.
