# UE5 Template Mismatch During Attaching of Instanced Component

**URL:** <https://forums.unrealengine.com/t/ue5-template-mismatch-during-attaching-of-instanced-component/1510733>\
**Category:** Programming & Scripting\
**Tags:** UE-5, unreal-engine, question, CPP\
**Created:** [December 9, 2023, 3:28pm UTC](https://forums.unrealengine.com/t/ue5-template-mismatch-during-attaching-of-instanced-component/1510733 "2023-12-09T15:28:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Paul\_Bronowski](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Paul\_Bronowski](https://forums.unrealengine.com/u/Paul_Bronowski)\
**Post date:** [March 1, 2024, 5:25pm UTC](https://forums.unrealengine.com/t/ue5-template-mismatch-during-attaching-of-instanced-component/1510733/2 "2024-03-01T17:25:36Z")

</div>

This worked for me…

```auto
void UMyComponent::OnRegister()
{
    Super::OnRegister();

    // TODO: BUGBUG: Work around the 'Template Mismatch during attachment. Attaching instanced component to template component.' problem.
    // Remove after Epic acknowledges and fixes this long-standing bug or provides guidance.
    // The constructor-initialized components, upon non-CDO instantiation/initialization, are getting CDO references for their attached parents, instead of instance references.
    // A work-around...
    // - Use SetupAttachment(), per usual in the constructor to establish the parent-child relationship for CDOs.
    // - Use AttachToComponent() to override those errant CDO references with instance references, in your USceneComponent::OnRegister() override.
    this->MySubComponent1->AttachToComponent(this->GetAttachmentRoot(), FAttachmentTransformRules::KeepRelativeTransform);
    this->MySubComponent2->AttachToComponent(this->MySubComponent1, FAttachmentTransformRules::KeepRelativeTransform);
}
```

---

_[View the full topic](https://forums.unrealengine.com/t/ue5-template-mismatch-during-attaching-of-instanced-component/1510733)._
