# Attaching a USceneComponent to another USceneComponent crashes with Template Mismatch (works in Development)

**URL:** <https://forums.unrealengine.com/t/attaching-a-uscenecomponent-to-another-uscenecomponent-crashes-with-template-mismatch-works-in-development/772426>\
**Category:** C++\
**Tags:** UE-5, unreal-engine, Components, CPP\
**Created:** [February 16, 2023, 8:50pm UTC](https://forums.unrealengine.com/t/attaching-a-uscenecomponent-to-another-uscenecomponent-crashes-with-template-mismatch-works-in-development/772426 "2023-02-16T20:50:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlfredBaudisch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alfredbaudisch/32/556329_2.png) [@AlfredBaudisch](https://forums.unrealengine.com/u/AlfredBaudisch)\
**Post date:** [February 16, 2023, 8:50pm UTC](https://forums.unrealengine.com/t/attaching-a-uscenecomponent-to-another-uscenecomponent-crashes-with-template-mismatch-works-in-development/772426/1 "2023-02-16T20:50:53Z")

</div>

UE 5.1. Considering I have the following component `UTileInteractionComponent : public USceneComponent` and inside it I have another component:

```cpp
class GAME_API UTileInteractionComponent : public USceneComponent
{
	GENERATED_BODY()

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta = (AllowPrivateAccess = "true"))
	UArrowComponent* ArrowComponent;
// ...
}

// -----------------------------
// Constructor...
// -----------------------------
UTileInteractionComponent::UTileInteractionComponent()
{
	PrimaryComponentTick.bCanEverTick = false;
	ArrowComponent = CreateDefaultSubobject<UArrowComponent>(TEXT("TraceTilesDirectionArrow"));
	ArrowComponent->AttachToComponent(this, FAttachmentTransformRules::KeepRelativeTransform);
	ArrowComponent->SetRelativeRotation(FRotator(-90.f, 0.f, 0.f));
}

```

A `UTileInteractionComponent` is instantiated into a `Character`:

```cpp
ABuilderCharacter::ABuilderCharacter()
{
	TileInteractionComponent = CreateDefaultSubobject<UTileInteractionComponent>(TEXT("Tile Interaction Component"));	TileInteractionComponent->SetupAttachment(RootComponent);
}

```

**It works in `DevelopmentEditor`, but it crashes in `Shipping`:**

```bash
Error LogOutputDevice Ensure condition failed: false [File:D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 2004] 
Error LogOutputDevice Template Mismatch during attachment. Attaching instanced component to template component. Parent 'Tile Interaction Component' (Owner 'Default__BP_ThirdPersonCharacter_C') Self 'TraceTilesDirectionArrow' (Owner 'BP_ThirdPersonCharacter_C_0').

```

The culprit is `ArrowComponent->AttachToComponent(this, FAttachmentTransformRules::KeepRelativeTransform);` inside `UTileInteractionComponent`.

How to have this component hierarchy **Character → Component → InnerComponent** , while being able to attach the inner component with `FAttachmentTransformRules::KeepRelativeTransform`?

Maybe related - seems that it’s still a bug with UE 5.1?

- [Attaching one component to another crash: 'template mismatch during attachment' - #23 by thomasm](https://forums.unrealengine.com/t/attaching-one-component-to-another-crash-template-mismatch-during-attachment/11645/23)
- [Adding UBoxComponent to a custom PlayerStart class crashes gameplay](https://forums.unrealengine.com/t/adding-uboxcomponent-to-a-custom-playerstart-class-crashes-gameplay/294074)

Other questions kind of related:

- [Correct way of setting up hierarchy for USceneComponent and UActorComponent](https://forums.unrealengine.com/t/correct-way-of-setting-up-hierarchy-for-uscenecomponent-and-uactorcomponent/691526)
- [USceneComponent\* MuzzleLocation;](https://forums.unrealengine.com/t/uscenecomponent-muzzlelocation/474140)

---

<div class="post-metadata">

**Author:** ![AlfredBaudisch](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/alfredbaudisch/32/556329_2.png) [@AlfredBaudisch](https://forums.unrealengine.com/u/AlfredBaudisch)\
**Post date:** [February 17, 2023, 10:06am UTC](https://forums.unrealengine.com/t/attaching-a-uscenecomponent-to-another-uscenecomponent-crashes-with-template-mismatch-works-in-development/772426/2 "2023-02-17T10:06:13Z")

</div>

I didn’t solve the problem reported, but I made the game work by removing the inner `UArrowComponent` from `UTileInteractionComponent`, and I made `UTileInteractionComponent` inherit from `UArrowComponent`.

So it’s not a “composable component” anymore, but at least it doesn’t crash anymore.
