ChildActorComponent: ChildActorTemplate causes crash when native child actor class changed

The crash occurs when native child class used in the ChildActorComponent has been changed and new native components have been added. To reproduce that I have created two C++ actors and one of those contains a ChildActorComponent:

ParentActor.h

UCLASS()
class TEST_API AParentActor : public AActor
{
GENERATED_BODY()
public:	

AParentActor();

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Instanced, Category = Test)
class UChildActorComponent* ChildActorComponent;
};

ParentActor.cpp

AParentActor::AParentActor()
{
ChildActorComponent = CreateDefaultSubobject<UChildActorComponent>(TEXT("ChildActorComponent"));
ChildActorComponent->SetupAttachment(GetRootComponent());

}

ChildActor.h

UCLASS()
class TEST_API AChildActor : public AActor
{
 GENERATED_BODY()
 public:	

    AChildActor();	
};

ChildActor.cpp

AChildActor::AChildActor()
{

}

Then I have created two blueprints for those actors and assigned ChildActor blueprint class as a class of Parent’s ChildActorComponent. ChildActorComponent creates and set its ChildActorTemplate.

After closing the editor I have added a new component to the child class:

ChildActor.h

UPROPERTY(VisibleDefaultsOnly, BlueprintReadOnly, Category = Collision)
UCapsuleComponent* CollisionComponent;

ChildActor.cpp

AChildActor::AChildActor()
{
   CollisionComponent= CreateDefaultSubobject<UCapsuleComponent>(TEXT("CollisionComponent"));
   if (CollisionComponent)
   {
	   SetRootComponent(CollisionComponent);
   }
}

After that change the editor is crashing all the time on loading of the parent blueprint (when I try to open that blueprint for editing) failing to find an Outer for that new component.

checkf(SubobjectOuter, TEXT("No corresponding destination object found for '%s' while attempting to instance component '%s'"), *SourceSubobject->GetOuter()->GetFullName(), *SourceSubobject->GetFullName());

Here is a call stack:

UE4Editor-CoreUObject.dll!FObjectInstancingGraph::GetInstancedSubobject(UObject * SourceSubobject, UObject * CurrentValue, UObject * CurrentObject, bool bDoNotCreateNewInstance, bool bAllowSelfReference) Line 181 C++
UE4Editor-CoreUObject.dll!FObjectInstancingGraph::InstancePropertyValue(UObject * ComponentTemplate, UObject * CurrentValue, UObject * Owner, bool bIsTransient, bool bCausesInstancing, bool bAllowSelfReference) Line 280 C++
UE4Editor-CoreUObject.dll!UObjectPropertyBase::InstanceSubobjects(void * Data, const void * DefaultData, UObject * Owner, FObjectInstancingGraph * InstanceGraph) Line 34 C++
UE4Editor-CoreUObject.dll!UStruct::InstanceSubobjectTemplates(void * Data, const void * DefaultData, UStruct * DefaultStruct, UObject * Owner, FObjectInstancingGraph * InstanceGraph) Line 1456 C++
UE4Editor-CoreUObject.dll!FObjectInitializer::InstanceSubobjects(UClass * Class, bool bNeedInstancing, bool bNeedSubobjectInstancing) Line 2942 C++
UE4Editor-CoreUObject.dll!FObjectInitializer::PostConstructInit() Line 2826 C++
UE4Editor-CoreUObject.dll!FObjectInitializer::~FObjectInitializer() Line 2684 C++
UE4Editor-CoreUObject.dll!StaticConstructObject_Internal(UClass * InClass, UObject * InOuter, FName InName, EObjectFlags InFlags, EInternalObjectFlags InternalSetFlags, UObject * InTemplate, bool bCopyTransientsFromClassDefaults, FObjectInstancingGraph * InInstanceGraph, bool bAssumeTemplateIsArchetype) Line 3212 C++
UE4Editor-Engine.dll!NewObject(UObject * Outer, UClass * Class, FName Name, EObjectFlags Flags, UObject * Template, bool bCopyTransientsFromClassDefaults, FObjectInstancingGraph * InInstanceGraph) Line 1227 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FTransform * UserTransformPtr, const FActorSpawnParameters & SpawnParameters) Line 405 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FVector * Location, const FRotator * Rotation, const FActorSpawnParameters & SpawnParameters) Line 271 C++
UE4Editor-Engine.dll!UChildActorComponent::CreateChildActor() Line 482 C++
UE4Editor-Engine.dll!UActorComponent::ExecuteRegisterEvents() Line 1179 C++
UE4Editor-Engine.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld) Line 912 C++
UE4Editor-Engine.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister) Line 4004 C++
UE4Editor-Engine.dll!AActor::RegisterAllComponents() Line 3940 C++
UE4Editor-Engine.dll!AActor::PostSpawnInitialize(const FTransform & UserSpawnTransform, AActor * InOwner, APawn * InInstigator, bool bRemoteOwned, bool bNoFail, bool bDeferConstruction) Line 2728 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FTransform * UserTransformPtr, const FActorSpawnParameters & SpawnParameters) Line 438 C++
UE4Editor-Engine.dll!UWorld::SpawnActor(UClass * Class, const FVector * Location, const FRotator * Rotation, const FActorSpawnParameters & SpawnParameters) Line 271 C++
UE4Editor-Kismet.dll!FBlueprintEditor::UpdatePreviewActor(UBlueprint * InBlueprint, bool bInForceFullUpdate) Line 8062 C++
UE4Editor-Kismet.dll!FBlueprintEditor::Tick(float DeltaTime) Line 7028 C++
UE4Editor-UnrealEd.dll!FTickableEditorObject::TickObjects(float DeltaSeconds) Line 17 C++
UE4Editor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1195 C++
UE4Editor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 371 C++
UE4Editor.exe!FEngineLoop::Tick() Line 2880 C++
UE4Editor.exe!GuardedMain(const wchar_t * CmdLine, HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, int nCmdShow) Line 152 C++
UE4Editor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow) Line 191 C++

If parent blueprint has been saved in the level then the level will also crash. It will not happen if ChildActorComponent of the parent uses a C++ class (ChildActor) instead of a blueprint one (based on ChildActor).

There are ways to load that object again:

  • By reverting a change that added a new component, opening parent blueprint and set a class for ChildActorComponent to None, reapplying code change and selecting blueprint class again
  • Or by turning off ChildActorTemplate functionality

Please let me know if those steps work for you in order to reproduce the issue.

There is another one related to the previous report. Here are steps to reproduce:

  • Follow all the steps from the original post but as a last step assign ChildActorClass in the parent’s ChildActorComponent
  • Restart the editor and make sure that the Parent actor can be spawned or at least opened for editing
  • Open a Child blueprint and add a reference to a Parent blueprint class, e.g. just add a cast to Parent blueprint class

124608-bpchild.jpg

  • Restart the editor and try to load Parent blueprint

  • The editor will crash here:

    void UActorComponent::OnRegister()
    {
    checkf(!IsUnreachable(), TEXT(“%s”), *GetDetailedInfo());
    checkf(!GetOuter()->IsTemplate(), TEXT(“‘%s’ (%s)”), *GetOuter()->GetFullName(), *GetDetailedInfo());
    checkf(!IsTemplate(), TEXT(“‘%s’ (%s)”), *GetOuter()->GetFullName(), GetDetailedInfo() );
    checkf(WorldPrivate, TEXT(“OnRegister: %s to %s”), GetDetailedInfo(), GetOwner() ? GetOwner()->GetFullName() : TEXT("
    No Owner **") );
    checkf(!bRegistered, TEXT(“OnRegister: %s to %s”), GetDetailedInfo(), GetOwner() ? GetOwner()->GetFullName() : TEXT("
    No Owner ***") );

A part of the callstack:

UE4Editor-Engine.dll!UActorComponent::OnRegister() Line 658 C++
UE4Editor-Engine.dll!USceneComponent::OnRegister() Line 570 C++
UE4Editor-Engine.dll!UPrimitiveComponent::OnRegister() Line 398 C++
UE4Editor-Engine.dll!UActorComponent::ExecuteRegisterEvents() Line 1179 C++
UE4Editor-Engine.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld) Line 912 C++
UE4Editor-Engine.dll!AActor::IncrementalRegisterComponents(int NumComponentsToRegister) Line 4004 C++
UE4Editor-Engine.dll!AActor::RegisterAllComponents() Line 3940 C++

Hey Sergey.Nt-

Thank you for submitting a bug report. I have reproduced this issue and logged a report for it here Unreal Engine Issues and Bug Tracker (UE-41708) . You can track the report’s status as the issue is reviewed by our development staff. Please be aware that this issue may not be prioritized or fixed soon.

Cheers

Thank you .

Upvoting this issue. I had an “Instance component attaching to template object” error with one of our C++ base classes whose BP child classes are often used as a child actor components of pawns. Now all our pawn BPs using those child BPs crash on open.

I was able to work around this issue by setting the ChildActorComponent’s class to the code derived blueprint from the parent’s BeginPlay blueprint event.

I believe this is a better workaround than the OP’s suggestion to change the ChildActorComponent to None, update, and then change back,