UStaticMeshComponent->SetPhysMaterialOverride crash

I took Puzzle basic template for c++ project. There I add in Block class pointer to phys material:

class UPhysicalMaterial* PhysMaterial;

And for now I initialize material through ConstructorHelpers and SetPhysMaterialOverride on UStaticMeshComponent with this material like this:

struct FConstructorStatics
    	ConstructorHelpers::FObjectFinderOptional<UPhysicalMaterial> PhysMaterial;
    		: PhysMaterial(TEXT("/Game/StonePhysicalMaterial"))

BlockMesh = CreateDefaultSubobject<UStaticMeshComponent>(TEXT("BlockMesh0"));

So when I play project in editor all works fine. But If I’m trying to launch project as a game, or just play standalone game through editor then application is crashed and report points to this line:


After that If I restart editor it’ll be not running with the same crash report. I sent report, my machine ID is 7B9A5253489C7324713D93A95783DC83

And 1 additional question. After first crash my level BP is broken too. It couldn’t to find BlueprintCallable function from my GameInstance class, I implemented there 4 BlueprintCallable functions(they successfully worked all past time and I didn’t change them), but level BP begins to see only first one. I don’t know why. Can anyone explain that?

Hey alkohol-

Where in code are you creating your struct? Additionally, ConstructorHelpers are only meant to be used inside of a constructor. Can you post the full setup for the class (.h and .cpp) where this code is so that I can follow your setup on my end? Also, can you post the callstack and logs from the crash?


Hi ,

Thank you for reply. Yes I do it in constructor. Log and sources are attached. I didn’t remove unnecessary code, maybe that affects something. Physical material is just physical material created within editor :slight_smile:

Hey alkohol-

Since you’re setting this in the constructor, the crash is likely caused by attempting to access something before the game has had the chance to create it. I found that placing what is line 12 in your original post inside an if(GetWorld()) call will prevent the crash. This tells the game to set the physical material only if the game world has already been created.


Thanks ,

that’s very impressive and interesting. I didn’t think about such possibility. Now I know one more thing which is worth checking out


Sorry for digging this up, but I’m having the same problem.

I tried to use your workaround, but I found that GetWorld() is always NULL in the constructor… So, although it does not crash, it does load the material either… ever. Not even when reloading the map.