After migrating to UE 4.18 all destructible meshes in our game stopped working, except when running the game on PIE.
Debugging a little bit, I found at the moment of deserializing in UDestructibleMesh::Serialize the deserialized ApexAsset is NULL if running as cooked standalone game, but deserializes correctly if running from editor.
The cooking process didn’t give me any warning regarding destructible meshes. Any idea what I should be looking into?
UPDATE:
Debugging further I’ve found the NvParameterized serializer didn’t have the factory for “DestructibleAssetParameters” version 26 registered at the time of loading the destructible mesh assets.
Seems like the reason our destructible meshes are working fine when running from Editor is because Apex Destruction is properly initialized before the game assets are loaded, however, when running standalone (a configuration without editor) the game assets are loaded before FApexDestructionModule::StartupModule is called.
Is there a way I can force the module to load first?
My work around was to load the DestructionModule when Apex is first initialized, instead of doing it in the plugin StartupModule (basically restoring what it was doing before 4.18).
I think other possible solution would be to not have any startup asset reference destructible assets (no direct or indirect references through base classes, singleton, etc), so that any destructible asset is loaded after all plugins have been initialized.
Basically added back LoadPhysicsLibrary for APEX_Destructible in PhysXLibs.cpp (right after Legacy and Clothing are loaded) instead of loading it in the plugin.
Thanks so much for this I really apreciate it! Ill try it when i get home and report back if it fixed the issue for me! But really thanks soo soo much. Theres so little info on apex destruction in c++.
Is loading the libary all i need to do? Or do i need to add the lib back or anything?
Look at what it does with the others and try to replicate it, you may need to modify headers too. You can also look for old revisions of the source code to compare.
Yes, I got it working, it’s not too difficult, but is not a single line change either.
As I was telling you the key is loading the destructible module on PhysXLibs.cpp, you will need to add back an apex::ModuleDestructible* GApexModuleDestructible pointer on PhysicsPublic.h, make ApexDestructionModule.cpp use that instead of loading it inside the plugin, and instantiate the module on PhysLevel.cpp (just like it does with Clothing or Legacy). The other Apex modules can work as example, replicate what they do or use the old source code as example.
@JMigCarrier This requires a full engine rebuild, correct? That may be a huge issue for me since the class library I use for my mod toolkit will need to work on vanilla 4.18
I really needed the engine to behave like it did before 4.18 for a commercial project, so I modified it. But a simpler solution would be to not have any destructible mesh referenced by any of initial assets that the game loads (for instance, only have those referenced by actors placed in the level), in that way the destructible plugin would have been already initialized when we time comes to load those destructible meshes.