Creating a Static Mesh at runtime in a packaged build?

Hello,

We are attempting to import 3D models at runtime in a packaged build, and use them to create Static Meshes.
We have been able to create Procedural Meshes with no issue, however they seem to be more intensive and significantly slow the game down. We have also been able to create Static Meshes within the editor, however it uses code that is editor only thus will not allow the game to be packaged. Is there a way to create Static Meshes in a packaged build? or perhaps a more efficient way of importing 3D files?

Any help is greatly appreciated.
Thank you

1 Like

As far as I am aware, There is no support for this functionality. The recent update to ProceduralMesh is significantly faster, and you can trace the function calls to see how it generates a sceneproxy and passes it to the renderer. A static mesh asset is generated and serialized in the editor, and UStaticMesh::Build can only be called in editor. It would require moving a lot of vars/funcs from the private area of different classes and removing the #IF_WITH_EDITOR defines, which could significantly impact the performance of the engine.

This cooking process, kicked off by UStaticMesh::Build(), depends on various Editor-only functions and data, and that’s why you couldn’t update the UStaticMesh geometry at runtime.

But, in 4.25 a new function was added - UStaticMesh::BuildFromMeshDescriptions(). This function takes a list of FMeshDescriptions and initializes the rendering mesh data, allowing a UStaticMesh to be built at runtime. This build is not the same as the Editor-only ::Build() path - it skips various complex steps that are too slow to do at runtime (eg build Distance Field Lighting data) or not useful (eg generate lightmap UVs, which would be useless as you can’t bake new lightmaps at runtime).

1 Like