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

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.

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…

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;

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!

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.

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

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

Thank you very much :slight_smile:

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 on the these components which others have also reported.

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?

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?

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:

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!

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 :slight_smile: Let me know what you find about this issue.

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,

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