Attempting to call SetPhysMaterialOverride() in a component's C++ constructor causes the project to crash when opening it in the Editor.
UMyBoxComponent::UMyBoxComponent() { static ConstructorHelpers::FObjectFinder<UPhysicalMaterial> MyPhysMat(TEXT("/Game/DefaultPhysicalMaterial.DefaultPhysicalMaterial")); if (MyPhysMat.Succeeded()) { TheMaterial = MyPhysMat.Object; SetPhysMaterialOverride(TheMaterial); } }
RESULT:
The project crashes on launch due to an access violation error.
EXPECTED:
The project opens in the Editor.
WORKAROUND:
If the call to SetPhysMaterialOverride() is made in BeginPlay() instead of in the constructor, the project opens successfully in the Editor.
UE4Editor_Engine!FBodyInstance::GetComplexPhysicalMaterials() [bodyinstance.cpp:3230] UE4Editor_Engine!FBodyInstance::GetComplexPhysicalMaterials() [bodyinstance.cpp:3216] UE4Editor_Engine!FBodyInstance::UpdatePhysicalMaterials() [bodyinstance.cpp:628] UE4Editor_Engine!FBodyInstance::SetPhysMaterialOverride() [bodyinstance.cpp:3134] UE4Editor_TestPhysMat!UMyBoxComponent::UMyBoxComponent() [myboxcomponent.cpp:11] UE4Editor_CoreUObject!UClass::CreateDefaultObject() [class.cpp:2728] UE4Editor_CoreUObject!UObjectLoadAllCompiledInDefaultProperties() [uobjectbase.cpp:795] UE4Editor_CoreUObject!ProcessNewlyLoadedUObjects() [uobjectbase.cpp:869] UE4Editor_CoreUObject!TBaseStaticDelegateInstance<void __cdecl() [delegateinstancesimpl.h:1027] UE4Editor_Core!TBaseMulticastDelegate<void>::Broadcast() [delegatesignatureimpl.inl:937] UE4Editor_Core!FModuleManager::LoadModuleWithFailureReason() [modulemanager.cpp:487] UE4Editor_Projects!FModuleDescriptor::LoadModulesForPhase() [moduledescriptor.cpp:476] UE4Editor_Projects!FProjectManager::LoadModulesForProject() [projectmanager.cpp:69] UE4Editor!FEngineLoop::LoadStartupModules() [launchengineloop.cpp:2577] UE4Editor!FEngineLoop::PreInit() [launchengineloop.cpp:1992] UE4Editor!GuardedMain() [launch.cpp:127] UE4Editor!GuardedMainWrapper() [launchwindows.cpp:134] UE4Editor!WinMain() [launchwindows.cpp:210] UE4Editor!__scrt_common_main_seh() [exe_common.inl:253] kernel32!<Unknown> ntdll!<Unknown>
There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-62367 in the post.