SetAllMassScale crash on project startup

Hi,

I have a problem where if I call SetAllMassScale() in the constructor of a script the project will compile and run fine, however the project will crash on startup, even if that class isn’t used yet (it isn’t attached to an object or called by another class). I narrowed the crash down to check(GEngine->DefaultPhysMaterial != NULL); in the engine’s UPhysicalMaterial* FBodyInstance::GetSimplePhysicalMaterial() function. GEngine is a null pointer at this point, so I’m assuming the problem is that the engine hasn’t had time to start up properly before that line of code is called. I’m pretty new to Unreal, so my first question is: why does Unreal run my code when loading up if I don’t have any objects using the code yet? Is this something to do with how they’ve implemented reflection? My second question is: how can I tell which functions I should be able to call from a constructor and which I shouldn’t? Is there a way of knowing which functions will refer to GEngine?

Cheers for any help.

Try changing your code from SetAllMassScale(); to if ( !IsTemplate() ) SetAllMassScale();