Static mesh sub components error

Hello,

I have a problem with a class inherited from UStaticMeshComponent which holds sub components.
Relevant code looks like this:

Header:

#pragma once

#include "Components/StaticMeshComponent.h"
#include "AttachmentComponent.generated.h"

UCLASS()
class WAR_API UAttachmentComponent : public UStaticMeshComponent
{
	GENERATED_BODY()

public:
	UPROPERTY(EditAnywhere, Category = FlashlightComponent)
		USpotLightComponent * SpotLight;

	UPROPERTY(EditAnywhere, Category = FlashlightComponent)
		UStaticMeshComponent * FlareMesh;

Code:

#include "WAR.h"
#include "AttachmentComponent.h"
#include "UnrealNetwork.h"


UAttachmentComponent::UAttachmentComponent(const FObjectInitializer & ObjectInitializer)
	: Super(ObjectInitializer)
{
	SpotLight = ObjectInitializer.CreateDefaultSubobject<USpotLightComponent>(this, TEXT("SpotLight"));
	SpotLight->AttachParent = this;

	FName CollisionProfileName(TEXT("NoCollision"));
	FlareMesh = ObjectInitializer.CreateDefaultSubobject<UStaticMeshComponent>(this, TEXT("FlareMesh"));
	FlareMesh->AttachParent = this;
	FlareMesh->SetCollisionProfileName(CollisionProfileName);

	SetCollisionProfileName(CollisionProfileName);
	SetIsReplicated(true);
	AttachSocketName = FName(TEXT("root"));
}

When I add this component to an actor in the editor or start PIE, I get this error:

Ensure condition failed: false [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.8\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1149] 
Template Mismatch during attachment. Attaching instanced component to template component. Parent 'TRASH_Default__BP_Flashlight1_C_1' Self 'FlareMesh'
UE4Editor.exe has triggered a breakpoint.

Any idea why this is happening or how I can fix it?

Hi Fluppi393,

I used the code you provided to make a custom Static Mesh Component class, but did not see any problems when I added it to an Actor Blueprint and started PIE. Would you be able to clarify exactly how you are adding it?

Hello,

I created a Blueprint class which inherits from the custom component and then added it to an actor blueprint class.

I was able to reproduce the issue on a blank test project with this simple class:

#pragma once

#include "Components/StaticMeshComponent.h"
#include "TestComponent.generated.h"

UCLASS(Blueprintable, meta = (BlueprintSpawnableComponent))
class TESTPROJECT_API UTestComponent : public UStaticMeshComponent
{
	GENERATED_BODY()
	
public:
	UPROPERTY(EditAnywhere, Category = Default)
		USpotLightComponent * SpotLight;

	UTestComponent(const FObjectInitializer & ObjectInitializer);
	
};

//.cpp
#include "TestProject.h"
#include "TestComponent.h"

UTestComponent::UTestComponent(const FObjectInitializer & ObjectInitializer)
	: Super(ObjectInitializer)
{
	SpotLight = ObjectInitializer.CreateDefaultSubobject<USpotLightComponent>(this, TEXT("SpotLight"));
	SpotLight->AttachParent = this;
}

When I add the pure c++ component to a blueprint it works fine, but when I add a blueprint component which inherits from the c++ class the engine will crash with the error mentioned above.

Thank you for the clarification. I believe I am seeing the same thing that you described, but would it be possible to get the full callstack that you receive so I can compare that to what I am getting?

I am sorry due to another problem I cannot compile any project right now, but I remember that the assertion that lead to the crash was something like

check(IsTemplate() == Outer->IsTemplate());

Hope this helps for now as soon as I can compile again I will send you the callstack.

Hi Fluppi393,

I have entered a report of the Ensure that I was seeing, which I believe is the same thing that you were seeing (UE-20322). It does seem to be unexpected that you would see an Ensure when using a Blueprinted component, but no Ensure when using the native version of the same component. Unfortunately I do not have a workaround for this.

Seeing this too. can repro, +1 vote.

I also run into this with blueprinted character class used in ChildActorComponent, when the base character class doesn’t run into this issue. Similar behaviour to StaticMeshComponent.

Only workaround I can think of is copy pasting engine’s ChildActorComponent into own custom component, debugging and fixing the issue, and use the MyChildActorComponent component in place of the actual engine ChildActorComponent.

Would be great if Epic can help with fixed MyChildActorComponent code here!

UE4 also runs into a warning “SpawnActor in ConstructionScript” when attaching a child actor in the that spawns something, like a character spawning a controller.