Download

Crashes while using extended CharacterMovementComponent

I’m having trouble extending the CharacterMovementComponent in the Character class. I’ve gotten one of 3 errors each time I try to hotload the code into the editor. (Reloading the editor after compiling doesn’t seem to work either). Hopefully it’s just some syntax error in my declarations.

Here’s my code, and the errors at the bottom (This is using 4.7.2):

MyProjectCharacterMovementComponent.h


UCLASS()
class UMyProjectCharacterMovementComponent : public UCharacterMovementComponent
{
	GENERATED_BODY()
};

MyProjectCharacterMovementComponent.cpp


//No code as of yet

MyProjectCharacter.cpp (Version 1)


AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{
...

MyProjectCharacter.cpp (Version 2)


AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	if (!HasAnyFlags(RF_TagGarbageTemp))
	{
		ObjectInitializer.SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>(ACharacter::CharacterMovementComponentName);
	}
...

MyProjectCharacter.cpp (Version 3)


AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
	if (!HasAnyFlags(RF_TagGarbageTemp))
	{
		ObjectInitializer.SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>(ACharacter::CharacterMovementComponentName);
	}
...

Version 1 error


Unknown exception - code 00000001 (first/second chance not available)

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 1639] 
Object is not packaged: None None

KERNELBASE + 37901 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 292 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FMsg::Logf__VA() + 463 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\misc\outputdevice.cpp:526]
UE4Editor_CoreUObject!StaticAllocateObjectErrorTests() + 941 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1639]
UE4Editor_CoreUObject!StaticAllocateObject() + 197 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1688]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() + 319 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:2502]
UE4Editor_CoreUObject!FObjectInitializer::CreateDefaultSubobject() + 569 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2644]
UE4Editor_CoreUObject!UObject::CreateDefaultSubobject() + 419 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\obj.cpp:62]
UE4Editor_Engine!ACharacter::ACharacter() + 888 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\character.cpp:77]

Version 2 error


Unknown exception - code 00000001 (first/second chance not available)

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 2193] 
MyProjectCharacter //Engine//Transient.Default__MyProjectCharacter.CharMoveComp: Subobject cl

KERNELBASE + 37901 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 292 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FMsg::Logf__VA() + 463 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\misc\outputdevice.cpp:526]
UE4Editor_CoreUObject!FObjectInitializer::AssertIfSubobjectSetupIsNotAllowed() + 209 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2193]
UE4Editor_MyProject_3347_Win64_DebugGame!FObjectInitializer::SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>() + 178 bytes [e:\unreal engine\epic games\4.7\engine\source\runtime\coreuobject\public\uobject\uobjectglobals.h:731]
UE4Editor_MyProject_3347_Win64_DebugGame!AMyProjectCharacter::AMyProjectCharacter() + 233 bytes [e:\unreal projects\game1\myproject\source\myproject\myprojectcharacter.cpp:17]

Version 3 error


Unknown exception - code 00000001 (first/second chance not available)

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 1639] 
Object is not packaged: None None

KERNELBASE + 37901 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 292 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FMsg::Logf__VA() + 463 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\misc\outputdevice.cpp:526]
UE4Editor_CoreUObject!StaticAllocateObjectErrorTests() + 941 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1639]
UE4Editor_CoreUObject!StaticAllocateObject() + 197 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1688]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() + 319 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:2502]
UE4Editor_CoreUObject!FObjectInitializer::CreateDefaultSubobject() + 569 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2644]
UE4Editor_MyProject_917_Win64_DebugGame!AMyProjectCharacter::AMyProjectCharacter() + 364 bytes [e:\unreal projects\game1\myproject\source\myproject\myprojectcharacter.cpp:17]

Just start your game in debug mode and look at the line where it throws.

=> Hit F5 in Visual Studio for debugging.

It crashes during hotload , when it tries to initialize the custom CharacterMovementComponent.

Overriding base class default subobjects is a bit special due to the nature of C++ constructors. C++ constructs objects starting from the basemost class and works its way up to the top. So when you are inside the AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer) constructor proper, ACharacter has already been constructed and it is too late to override the default subobject.

Therefore, the syntax to override or disable base class subobjects has to be passed down to the base class through the Super constructor. This is why SetDefaultSubobjectClass returns a FObjectInitializer reference, so you can modify it before passing it to the base class. Here’s how you would do it:



AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>(ACharacter::CharacterMovementComponentName)
{
	// ctor body
}

-Camille

Camille is correct!

For others, and for future reference, I made a wiki on this subject a while back here:

Wiki: Custom Character Movement Component


**Note On Subclassing / Blueprinting C++ Class**

Be careful when subclassing a C++ class that uses this structure, **you can't change the custom movement component later** without having blueprinted versions of this class completely freak out.

Since you usually blueprint character C++ classes, this is an important precaution to remember!

Rama

Thanks for the answers. Yeah, you’ll see that I attempted to use that method of initialization in Version 1 of my code (Versions 2 and 3 are different approaches). The crash is also listed in the opening post (Under Version 1).

Rama, is this then the issue you referred to when you said “without having blueprinted versions of this class completely freak out.”?

How do I fix this then? Do I need to recreate the blueprint of the character?

Edit: The error seems to persist even after I deleted all blueprints of the original class from the project.

Edit2: To avoid confusion, here’s the code and the error again:

MyProjectCharacter.cpp


AMyProjectCharacter::AMyProjectCharacter(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer.SetDefaultSubobjectClass<UMyProjectCharacterMovementComponent>(ACharacter::CharacterMovementComponentName))
{

Error


Unknown exception - code 00000001 (first/second chance not available)

Fatal error: [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.7\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 1644] 
Object is not packaged: None None

KERNELBASE + 37901 bytes
UE4Editor_Core!FOutputDeviceWindowsError::Serialize() + 292 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\windows\windowsplatformoutputdevices.cpp:95]
UE4Editor_Core!FMsg::Logf__VA() + 463 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\misc\outputdevice.cpp:526]
UE4Editor_CoreUObject!StaticAllocateObjectErrorTests() + 941 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1644]
UE4Editor_CoreUObject!StaticAllocateObject() + 197 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1693]
UE4Editor_CoreUObject!UClass::CreateDefaultObject() + 319 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:2502]
UE4Editor_CoreUObject!FObjectInitializer::CreateDefaultSubobject() + 569 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2649]
UE4Editor_CoreUObject!UObject::CreateDefaultSubobject() + 419 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\obj.cpp:62]
UE4Editor_Engine!ACharacter::ACharacter() + 888 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\engine\private\character.cpp:77]
UE4Editor_MyProject_3972_Win64_DebugGame!AMyProjectCharacter::AMyProjectCharacter() + 117 bytes [e:\unreal projects\game1\myproject\source\myproject\myprojectcharacter.cpp:10]
UE4Editor_MyProject_3972_Win64_DebugGame!AMyProjectCharacter::__DefaultConstructor() + 76 bytes [e:\unreal projects\game1\myproject\source\myproject\myprojectcharacter.h:9]
UE4Editor_MyProject_3972_Win64_DebugGame!InternalConstructor<AMyProjectCharacter>() + 40 bytes [e:\unreal engine\epic games\4.7\engine\source\runtime\coreuobject\public\uobject\class.h:2238]
UE4Editor_CoreUObject!StaticConstructObject() + 1444 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:2237]
UE4Editor_CoreUObject!UClass::HotReloadPrivateStaticClass() + 397 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\class.cpp:3368]
UE4Editor_MyProject_3972_Win64_DebugGame!GetPrivateStaticClassBody<AMyProjectCharacter>() + 526 bytes [e:\unreal engine\epic games\4.7\engine\source\runtime\coreuobject\public\uobject\class.h:2279]
UE4Editor_MyProject_3972_Win64_DebugGame!AMyProjectCharacter::GetPrivateStaticClass() + 78 bytes [e:\unreal projects\game1\myproject\intermediate\build\win64\inc\myproject\myproject.generated.cpp:50]
UE4Editor_MyProject_3972_Win64_DebugGame!TClassCompiledInDefer<AMyProjectCharacter>::Register() + 42 bytes [e:\unreal engine\epic games\4.7\engine\source\runtime\coreuobject\public\uobject\uobjectbase.h:296]
UE4Editor_CoreUObject!UClassRegisterAllCompiledInClasses() + 176 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:690]
UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() + 11 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\coreuobject\private\uobject\uobjectbase.cpp:808]
UE4Editor_CoreUObject!TBaseStaticDelegateInstance<void __cdecl(void)>::ExecuteIfSafe() + 7 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegateinstancesimpl_variadics.inl:921]
UE4Editor_Core!TBaseMulticastDelegate<void>::Broadcast() + 149 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\delegates\delegatesignatureimpl_variadics.inl:1030]
UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() + 2194 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\modules\modulemanager.cpp:359]
UE4Editor_Core!FModuleManager::LoadModule() + 56 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\private\modules\modulemanager.cpp:238]
UE4Editor_HotReload!FHotReloadModule::DoHotReloadInternal() + 648 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\developer\hotreload\private\hotreload.cpp:654]
UE4Editor_HotReload!FHotReloadModule::DoHotReloadFromIDE() + 1660 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\developer\hotreload\private\hotreload.cpp:1059]
UE4Editor_HotReload!FHotReloadModule::Tick() + 112 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\developer\hotreload\private\hotreload.cpp:995]
UE4Editor!FTicker::Tick() + 698 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\core\public\containers	icker.h:90]
UE4Editor!FEngineLoop::Tick() + 6356 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launchengineloop.cpp:2352]
UE4Editor!GuardedMain() + 1404 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\launch.cpp:142]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:126]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.7\engine\source\runtime\launch\private\windows\launchwindows.cpp:202]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

I moved this issue to the AnswerHub (It’s probably more appropriate there).

Try rebuilding outside of a hot reload? (i.e.: compile your game project without the editor running)