# \[UE 4.8\] Error on playing game when an actor of a custom class is placed in the level

**URL:** <https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655>\
**Category:** Community & Industry Discussion\
**Tags:** error, actor, unreal-engine, component, template, question\
**Created:** [June 13, 2015, 10:34am UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655 "2015-06-13T10:34:41Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 13, 2015, 10:34am UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/1 "2015-06-13T10:34:41Z")

</div>

Hello, i updated to 4.8 and i when i place an actor on the level of a class i made and play the game i get this error:

Ensure condition failed: false [File:C:\UnrealEngine\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1149]  
Template Mismatch during attachment. Attaching instanced component to template component. Parent ‘Mesh’ Self ‘Collider’

The editor doesn’t crash and allows me to continue, but the actor doesn’t collide. Here is the init code for the collider:

```
.h

UPROPERTY(VisibleDefaultsOnly, BlueprintReadWrite, Category = "Collision")
UBoxComponent * CollisionComp;

.cpp

CollisionComp = ObjectInitializer.CreateDefaultSubobject<UBoxComponent>(this, TEXT("Collider"));
CollisionComp->InitBoxExtent(FVector(1.0f, 1.0f, 1.0f));
CollisionComp->OnComponentBeginOverlap.AddDynamic(this, &AMyClass::OnOverlap);
CollisionComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
CollisionComp->SetCollisionResponseToAllChannels(ECollisionResponse::ECR_Ignore);
CollisionComp->SetCollisionResponseToChannel(ECollisionChannel::ECC_Pawn, ECollisionResponse::ECR_Overlap);
	
CollisionComp->AttachParent = RootComponent;

```

This worked in 4.7.

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [June 15, 2015, 2:00pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/2 "2015-06-15T14:00:13Z")

</div>

Same issue here. Also, the editor _does_ crash if you launch your game from Visual Studio but when you launch from uproject it tends to just silently print the message onto logs and move on. Any affected actor is translated to world origin (0,0,0) as a result. Trying to find a workaround…

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 15, 2015, 3:40pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/3 "2015-06-15T15:40:25Z")

</div>

Hi xlar8or,

If I am reading your code correctly, the collision for this CollisionComp is being set to ‘NoCollision’ and it’s response is set to ‘Ignore’. Could you try setting it to CollisionEnabled and setting the response to ‘Block’ to see if the collision is working? If that does not work, this could be related to another issue. To see if it is, please try moving the following line out of the constructor and into a call of PostInitProperties:

```
CollisionComp->AttachParent = RootComponent;

```

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [June 15, 2015, 6:46pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/4 "2015-06-15T18:46:06Z")

</div>

Thanks to 's tip I managed to workaround my issue by moving attachment of components to _PostInitializeComponents_ instead of the constructor. Just like OP mentioned, this code was working without issues in 4.7 so I’m curious to know what changes in 4.8 may have triggered this issue.

PS: I realize that suggested moving to _PostInitProperties_ but this did not work for me so I used PostInitializeComponents instead. Secondly, even from PostInitializeComponents I was forced to use “AttachTo” syntax as opposed to setting the AttachParent for it to work. I’m not entirely convinced with my workaround but it helps me move forward for now with 4.8 at least!

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 15, 2015, 7:10pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/5 "2015-06-15T19:10:38Z")

</div>

Ah, I didn’t even think about the fact that we were setting a component. Of course you’d use PostInitializeComponents. Thank you for the reply, VSZ.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 15, 2015, 7:24pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/6 "2015-06-15T19:24:19Z")

</div>

I will try it asap and let you know. Any idea why this behavior changed in 4.8?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 15, 2015, 7:43pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/7 "2015-06-15T19:43:40Z")

</div>

I’m currently looking into if the change was intended or not. I’ll let you know as soon as I find out more.

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 15, 2015, 7:44pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/8 "2015-06-15T19:44:18Z")

</div>

Thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [June 16, 2015, 11:00am UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/9 "2015-06-16T11:00:13Z")

</div>

Update: With the workaround I get intermittent crashes after exiting a play session with an error " Object from PIE level still referenced" so I’m not 100% there yet.

There’s also another issue with overlap events [not generating](https://answers.unrealengine.com/questions/242627/cant-enter-box-collision-with-overlapall-preset-in.html) on the these components which others have also reported.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 16, 2015, 9:46pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/10 "2015-06-16T21:46:36Z")

</div>

Hi again Xlar8or and VSZ,

While looking into the issue I tried using the exact code that xlar8or gave in the original post. All of the code works but the problem is that, in this case, there is no root component so there is nothing for it to attach to in the last line. After noticing this I made a UStaticMeshComponent to be the root component then tried using AttachParent and AttachTo in the constructor to attach the BoxCollider to the root component without any issues.

After making a root component, do you still run into this issue?

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 16, 2015, 10:14pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/11 "2015-06-16T22:14:00Z")

</div>

In my case my root component is a skeletal mesh that is set in a parent class. I tried CollisionComp-\>AttachTo(RootComponent); in PostInitializeComponents and it no longer crashes, but the collision is not working.

**Update:** The collision is working, my logic for some reason is not working.

**Update 2:** The problem is not my logic, for some reason the collision is begin triggered not by my instance MyClass\_BP\_2, but from Default\_\_MyClass\_BP\_C.

**Update 3:** I added the OnComponentBeginOverlap line to the original question i forgot to put. If i move that to PostInitializeComponents() before the AttachTo() it starts calling it on Default\_\_MyClass\_BP\_C and my instance MyClass\_BP\_2, so right now it’s working as it should. My question right now is, why is this happening?

---

<div class="post-metadata">

**Author:** ![VSZ](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@VSZ](https://forums.unrealengine.com/u/VSZ)\
**Post date:** [June 17, 2015, 9:30am UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/12 "2015-06-17T09:30:41Z")

</div>

I do have a root component. I’m able to reproduce my issue cleanly on a fresh project as well, I logged a separate bug report yesterday with a list of all the attachment/collision related issues I’m seeing and uploaded two sample projects where you can see the issue:

> **[4.8 Major issues in attaching child component and Overlap trigger (With repro)](https://forums.unrealengine.com/questions/243539/48-major-issues-in-attaching-child-component-and-o.html)**
>
> Summary of issues: Issue 1) Attaching a child component (eg: SphereComponent) from C++ code to an Actor’s root in 4.8 results in an error on PIE with the message Template Mismatch during attachment. Attaching instanced component to template...

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 18, 2015, 4:42pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/13 "2015-06-18T16:42:13Z")

</div>

Hi xlar8or,

Due to other users who were reporting similar issues, I’ve been looking at this in different projects and it seems as though if a UProperty is set to either VisibleDefaultsOnly or EditDefaultsOnly, attempting to attach it in the constructor in 4.8 causes these issues. Can you try changing the UProperty specifiers for your CollisionComp to EditAnywhere and see if the original issue persists when attempting to attach it in the constructor? As to why VisibleDefaultsOnly and EditDefaultsOnly are causing this issue, I’m currently looking into this and will update you with any information I come up with.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 18, 2015, 5:05pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/14 "2015-06-18T17:05:07Z")

</div>

I can confirm that this is what happens to me too. If i set to EditAnywhere it works great, revert it to other property it crashes. Thank you for your help 🙂 Let me know what you find about this issue.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_41845f4a](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_41845f4a](https://forums.unrealengine.com/u/anonymous_user_41845f4a)\
**Post date:** [June 23, 2015, 2:16pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/15 "2015-06-23T14:16:37Z")

</div>

We’re still unsure of why exactly this issue is occurring but a bug has been put into our database for the issue. For your reference, the bug number is UE-17400.

Have a nice day,

---

<div class="post-metadata">

**Author:** ![xlar8or](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/xlar8or/32/710746_2.png) [@xlar8or](https://forums.unrealengine.com/u/xlar8or)\
**Post date:** [June 23, 2015, 2:24pm UTC](https://forums.unrealengine.com/t/ue-4-8-error-on-playing-game-when-an-actor-of-a-custom-class-is-placed-in-the-level/321655/16 "2015-06-23T14:24:10Z")

</div>

Thnks for the follow-up 🙂 Hope to see this fixed in 4.9 or sooner 🙂 For now i’ll use the EditAnywhere workaround.
