Package crashing when creating UChildActorComponent in C++

Hi everyone, I have this on my custom character class:

UPROPERTY(EditDefaultsOnly, Category = "Properties|Senses")
UChildActorComponent* SensesComponent;

Then in the constructor I have this:

SensesComponent = CreateDefaultSubobject<UChildActorComponent>(TEXT("CharacterBase_SensesComp"));

All my functionality works fine on the editor, but when I make a package… crashes with 34 errors, and the errors are the following:

UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:687][  0]LogInit:Display: LogOutputDevice:Error: Ensure condition failed: AttachParent == nullptr || !AttachParent->AttachChildren.Contains(this) [File:D:\Build\++UE4+Release-4.15+Compile\Sync\Engine\Source\Runtime\Engine\Private\Components\SceneComponent.cpp] [Line: 1557]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:687][  0]LogInit:Display: LogOutputDevice:Error: SetupAttachment cannot be used once a component has already had AttachTo used to connect it to a parent.
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:687][  0]LogInit:Display: LogOutputDevice:Error: Stack: 
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:688][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Core.dll!FWindowsPlatformStackWalk::StackWalkAndDump() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\windows\windowsplatformstackwalk.cpp:200]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:688][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Core.dll!FDebug::EnsureFailed() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:233]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:689][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Core.dll!FDebug::OptionallyLogFormattedEnsureMessageReturningFalse() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\private\misc\assertionmacros.cpp:360]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:689][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Engine.dll!USceneComponent::SetupAttachment() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\components\scenecomponent.cpp:1557]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:690][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Engine.dll!ADirectionalLight::ADirectionalLight() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\light.cpp:248]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:690][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Engine.dll!InternalConstructor<ADirectionalLight>()
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:690][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!StaticConstructObject_Internal() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:3271]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:691][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!FLinkerLoad::CreateExport() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\linkerload.cpp:4031]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:691][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!FLinkerLoad::IndexToObject() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\linkerload.cpp:4370]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:692][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!FLinkerLoad::operator<<() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\linkerload.cpp:4581]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:692][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Engine.dll!operator<<() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\core\public\containers\array.h:1111]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:693][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Engine.dll!ULevel::Serialize() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\engine\private\level.cpp:353]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:693][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!FLinkerLoad::Preload() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\linkerload.cpp:3436]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:693][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!EndLoad() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1601]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:694][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!LoadPackageInternalInner() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1321]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:694][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-CoreUObject.dll!LoadPackage() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\coreuobject\private\uobject\uobjectglobals.cpp:1477]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:695][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-UnrealEd.dll!UCookOnTheFlyServer::TickCookOnTheSide() [d:\build\++ue4+release-4.15+compile\sync\engine\source\editor\unrealed\private\cookontheflyserver.cpp:1470]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:695][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-UnrealEd.dll!UCookCommandlet::NewCook() [d:\build\++ue4+release-4.15+compile\sync\engine\source\editor\unrealed\private\commandlets\cookcommandlet.cpp:1582]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:695][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-UnrealEd.dll!UCookCommandlet::Main() [d:\build\++ue4+release-4.15+compile\sync\engine\source\editor\unrealed\private\commandlets\cookcommandlet.cpp:868]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:696][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Cmd.exe!FEngineLoop::PreInit() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\launchengineloop.cpp:2005]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:696][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Cmd.exe!GuardedMain() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\launch.cpp:127]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:696][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Cmd.exe!GuardedMainWrapper() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:134]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:697][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Cmd.exe!WinMain() [d:\build\++ue4+release-4.15+compile\sync\engine\source\runtime\launch\private\windows\launchwindows.cpp:210]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:697][  0]LogInit:Display: LogOutputDevice:Error: UE4Editor-Cmd.exe!__scrt_common_main_seh() [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl:264]
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:698][  0]LogInit:Display: LogOutputDevice:Error: KERNEL32.DLL!0x0000000097AF8364
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:698][  0]LogInit:Display: LogOutputDevice:Error: ntdll.dll!0x0000000097F370D1
UATHelper: Packaging (Windows (64-bit)): UE4Editor-Cmd: [2017.04.04-15.00.26:698][  0]LogInit:Display: LogOutputDevice:Error: end: stack for UAT

If I comment that line the packages complete succesfully.
Don’t know what to do :frowning: definitely UChildActorComponent has something to do with this strange crash on the package.

Hey -

I copied the code provided into a character class and was able to package for Win64 successfully. I did notice in your log where it appears you’re using AttachTo followed by SetupAttachment. Can you provide the full code for the class for additional information?

I was able to resolve the issue, I found that the real problem was calling the following function just after the CreateDefaultSubobject on the constructor:

SensesComp->SetChildActorClass(ASensesComponent::StaticClass());

I moved that line to the BeginPlay function instead the constructor and everything works fine now on the package. I was calling also the CreateChildActor function after that line, but I realize that it’s not necessary.

Conclusion: Don’t use CreateChildActor and don’t use SetChildActorClass on the constructor.