Changing Parent Class of a C++ Class Crashes Editor

I am trying to change the parent class of my c++ class from USceneComponent to UStaticMeshComponent, which causes the editor to crash on recompile. I don’t find any existing qustions on the forum for this, so I guess I am overseeing something obvious? Is there some procedure to do this? The compiles finishes successfully in VS, but the editor crashes instantanious and also on startup.

Hey pulp_user-

In the header file you should be able to change public USceneComponent to public UStaticMeshComponent though changing the parent of a class in this way is not generally recommended. If you need a static mesh class, creating a new one would be safer and less likely to cause issue than attempting to change the parent of another. For further information, can you provide info on what changes you attempted to make to the class as well as the callstack and log files from the crash?

Cheers

Since comments have a character limit, I posted my reply as a new answer.

Thank you for the response! I did exactly what you said: public USceneComponentpublic UStaticMeshComponent

Which results in the crash. Here is the log:

Fatal error: [File:D:\Build\++UE4+Release-4.14+Compile\Sync\Engine\Source\Runtime\Core\Private\GenericPlatform\GenericPlatformMemory.cpp] [Line: 152] 
Ran out of memory allocating 18446743924453773296 bytes with alignment 0


UE4Editor_Core!FDebug::AssertFailed() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:332]
UE4Editor_Core!FGenericPlatformMemory::OnOutOfMemory() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\genericplatform\genericplatformmemory.cpp:153]
UE4Editor_Core!FMallocTBB::Realloc() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\hal\malloctbb.cpp:99]
UE4Editor_Engine!TArray::ResizeTo() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\containers\array.h:2256]
UE4Editor_Engine!TArray::Empty() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\containers\array.h:1548]
UE4Editor_Engine!operator<<() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\containers\array.h:1112]
UE4Editor_Engine!UStaticMeshComponent::Serialize() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\components\staticmeshcomponent.cpp:271]
UE4Editor_Engine!UEngine::CopyPropertiesForUnrelatedObjects() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\engine\private\unrealengine.cpp:11400]
UE4Editor_UnrealEd!FBlueprintCompileReinstancer::ReplaceInstancesOfClass_Inner() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\kismet2\kismetreinstanceutilities.cpp:1792]
UE4Editor_UnrealEd!FBlueprintCompileReinstancer::ReplaceInstancesOfClass() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\kismet2\kismetreinstanceutilities.cpp:1464]
UE4Editor_UnrealEd!FBlueprintCompileReinstancer::ReinstanceInner() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\kismet2\kismetreinstanceutilities.cpp:670]
UE4Editor_UnrealEd!FBlueprintCompileReinstancer::ReinstanceObjects() [d:\build\++ue4+release-4.14+compile\sync\engine\source\editor\unrealed\private\kismet2\kismetreinstanceutilities.cpp:901]
UE4Editor_HotReload!FHotReloadModule::ReinstanceClass() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\hotreload\private\hotreload.cpp:1232]
UE4Editor_HotReload!FHotReloadModule::ReinstanceClasses() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\hotreload\private\hotreload.cpp:1219]
UE4Editor_HotReload!TBaseRawMethodDelegateInstance<0,FHotReloadModule,void __cdecl(void)>::ExecuteIfSafe() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:639]
UE4Editor_CoreUObject!UClassReplaceHotReloadClasses() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:688]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:826]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance::ExecuteIfSafe() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegateinstancesimpl.h:1018]
UE4Editor_Core!TBaseMulticastDelegate::Broadcast() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\public\delegates\delegatesignatureimpl.inl:922]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\modules\modulemanager.cpp:466]
UE4Editor_Core!FModuleManager::LoadModule() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\modules\modulemanager.cpp:327]
UE4Editor_HotReload!FHotReloadModule::DoHotReloadInternal() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\hotreload\private\hotreload.cpp:828]
UE4Editor_HotReload!FHotReloadModule::DoHotReloadFromIDE() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\hotreload\private\hotreload.cpp:1453]
UE4Editor_HotReload!FHotReloadModule::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\developer\hotreload\private\hotreload.cpp:1386]
UE4Editor_Core!FTicker::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\core\private\containers\ticker.cpp:81]
UE4Editor!FEngineLoop::Tick() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2963]
UE4Editor!GuardedMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\launch.cpp:152]
UE4Editor!GuardedMainWrapper() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() [d:\build\++ue4+release-4.14+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
kernel32
ntdll

This was tested in a new class/project with nothing other than the auto-generated code which compiled after the change mentioned without a crash. Can you provide the class files so I can see what exactly your code is doing? Additionally, if you’re able to reproduce the crash in a new project, can you provide the setup steps used or the sample project itself for more information?

Sure, here they are. I want to be clear though: The compiler does not crash on my machine, just the editor.

Module.h:

    // Fill out your copyright notice in the Description page of Project Settings.
    
    #pragma once
    
//  #include "Components/SceneComponent.h"
    #include "Components/StaticMeshComponent.h"
    #include "InputMapping.h"
    #include "Module.generated.h"
    
    
    UCLASS()
    class THESPACEGAME_API UModule : public UStaticMeshComponent
//  class THESPACEGAME_API UModule : public USceneComponent
    {
    	GENERATED_BODY()
    
    public:	
    	UPROPERTY(EditAnywhere, Meta = (Control="PRETTY NAME"))
    		bool IsActivated;
    	UPROPERTY(EditAnywhere, Meta = (Control))
    		float MaxEnergyStorage;
    	UPROPERTY(EditAnywhere)
    		float CurrentEnergyStorage;
    	UPROPERTY(EditAnywhere)
    		float MaxEnergyInputRate;
    	UPROPERTY(EditAnywhere)
    		float CurrentEnergyInputRate;
    	UPROPERTY(EditAnywhere)
    		float EnergyInputRateLock;
    	UPROPERTY(EditAnywhere)
    		float EnergyInputModifier;
    	UPROPERTY(EditAnywhere)
    		float MaxEnergyOutputRate;
    	UPROPERTY(EditAnywhere)
    		float CurrentEnergyOutputRate;
    	UPROPERTY(EditAnywhere)
    		TArray<UInputMapping*> Mappings;
    	// Sets default values for this component's properties
    	UModule();
    
    	// Called when the game starts
    	virtual void BeginPlay() override;
    	
    	// Called every frame
    	virtual void TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction ) override;
    
    		
    	
    };

Module.cpp:

// Fill out your copyright notice in the Description page of Project Settings.

#include "TheSpaceGame.h"
#include "Module.h"


// Sets default values for this component's properties
UModule::UModule()
{
	// Set this component to be initialized when the game starts, and to be ticked every frame.  You can turn these features
	// off to improve performance if you don't need them.
	bWantsBeginPlay = true;
	PrimaryComponentTick.bCanEverTick = true;

	// ...
}


// Called when the game starts
void UModule::BeginPlay()
{
	Super::BeginPlay();

	// ...
	
}


// Called every frame
void UModule::TickComponent( float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction )
{
	Super::TickComponent( DeltaTime, TickType, ThisTickFunction );

	// ...
}

The changes I made to the header file were just the two commented lines at the top, altough the #include didn’t seem to matter, it compiles with and without the change made to it.

I tried copying your code into a new USceneComponent class and then converted the class to a UStaticMeshComponent class which compiled without a crash. If you switch your class back to USceneComponent are you able to open the project? If so can you create a new SceneComponent class and change that one to a StaticMeshComponent class? It may also help if you can provide the project where the crash is occurring.

I was able to find the reason: The class was used as a component in a blueprint-actor. As soon as I deleted the actor instances and the blueprint the editor didn’t crash. Deleting the instances is not enough however. I hope this is enough information to reproduce, if not I will send you my project. Do you know any way I could preserve my blueprint (there went quite some work into it)?

Hey pulp_user-

Thank you for the extra information. I was able to reproduce the crash after adding the component to a bluperint before changing the parent class. This has been reported here: Unreal Engine Issues and Bug Tracker (UE-39495) . 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

Ok, thank your very much for your time! I am always amazed by how quickly and dedicated you help people on the forums. Thanks!

I have the same issue in 4.19.2, did you find out any solution for it?

Watch this.

The video isn’t relevant, this question is regarding C++ parent classes in the OOP inheritance sense, not parent-child attachment of actors.

This issue (unless my crash was different) seems to be specific to UStaticMeshComponent, which has a custom Serialize function which writes “LODData” directly to the archive. Seems like a kind of ridiculous thing to do, given it’s a UPROPERTY marked explicitly as “Transient”, but it would probably be difficult to remove from the engine at this point.

In my case, I was trying to convert a StaticMeshComponent-derived component to inherit from something else. The workaround for my case was to serialize a dummy TArray in an overridden Serialize() function. This should work as long as the original StaticMeshComponent’s LODData was empty (int32 isn’t the right type, the real struct’s archive function isn’t exported).

For your case (reparenting to UStaticMeshComponent), you might be able to convert assets over by serializing an empty TArray if you’re saving, on the original type (override Serialize()). Re-save all affected assets, then switch the parent class.