Description

Attempting to call SetPhysMaterialOverride() in a component's C++ constructor causes the project to crash when opening it in the Editor.

Steps to Reproduce
  1. Create a new Basic Code project.
  2. Add a new code class to the project that derives from UBoxComponent.
  3. Copy one of the Engine's included physical materials to the project's Content folder.
  4. In the constructor of the new box component class, load the physical material from step 3 and use SetPhysMaterialOverride() to set the material.
    • eg.
      UMyBoxComponent::UMyBoxComponent()
      {
      	static ConstructorHelpers::FObjectFinder<UPhysicalMaterial> MyPhysMat(TEXT("/Game/DefaultPhysicalMaterial.DefaultPhysicalMaterial"));
      
      	if (MyPhysMat.Succeeded())
      	{
      		TheMaterial = MyPhysMat.Object;
      		SetPhysMaterialOverride(TheMaterial);
      	}
      }
      
  5. Build the project in Visual Studio.
  6. Open the project in the Editor.

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.

Callstack
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>

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-62367 in the post.

1
Login to Vote

Fixed
ComponentUE - Simulation - Physics
Affects Versions4.184.19.24.204.21
Target Fix4.23
Fix Commit7140823
Main Commit7165688
Release Commit7140823
CreatedAug 1, 2018
ResolvedJun 21, 2019
UpdatedFeb 11, 2020
View Jira Issue