Tutorial: Generating custom static meshes at Editor run-time

Very unfortunate indeed, I was just working on something like this yesterday and hadn’t seen this thread before you bumped it up again.

So what I ended up with yesterday uses the Custom/ProceduralMeshComponent and works pretty well for my case.
First I exposed both classes to blueprint (Blueprintable) so that they can be extended in the editor. For testing purposes I created one subclass for each one of the two classes, only to find out components don’t have a Construction Script in which I planned to create the geometry.
So I went back to my classes and added a BlueprintImplementableEvent, recompiled. Back in the editor I implemented this event in both blueprints adding a simple 2d square plane consisting of two triangles.
This component can now be used anywhere you like. Again for testing I created a new Actor blueprint subclass which uses both of my meshcomponent blueprints attached and positioned in the Viewport window. Finally in the Actor’s Construction Script I call the implemented functions on both components.

While this cannot give you StaticMesh assets like those you get from a regular import, it gives you StaticMeshComponents that allow you to generate a mesh for them at editor runtime.

Unfortunately that doesn’t work for me. I need to implement the Alembic just like the existing FBX importer so that I get a StaticMesh asset in the game content. This original post surely would have helped me get my head around at least part of it, as the FBX code is extremely vast, but oh well.

You can speed up the learning process if you search for UStaticMesh within fbx importer source files.

Bulk of Fbx code (*.cpp files) is located at “UnrealEngine\Engine\Source\Editor\UnrealEd\Private\Fbx”, where “UnrealEngine” is source code root folder. Looks like “FbxStaticMeshImport.cpp” should be of interest.

Basically, ignore anything that is not interacting with UStaticMesh and see which interaface methods/variables are available.

Yeah that is what I have been doing. Progress is slow but moving forward.

I think I am building the static mesh properly now, at least I no longer get any Raw Mesh errors when saving the mesh. However my package never shows up in the asset browser so something is still missing and I don’t think it is the package handling since that is pretty basic. Pretty sure I am still missing something on the Static Mesh or Raw Mesh side.

You probably forgot to mark package as dirty and notify asset registry that it has been created.



	if ( Asset != NewStaticMesh )
	{
		FAssetRegistryModule::AssetCreated(Asset);
		Asset->MarkPackageDirty();
	}
						}


The package creation follows same route everywhere (can be tempalted), and the part where you mark package as dirty AFTER you’ve created actual asset is easy to miss.

The part of fbx importer where it creates materials is easier to follow than static mesh, so you could look there for package creation part.

===

Also, please consider adding wiki article or just a post somewhere once you’ve figured out static meshes. few sentences with mentions of relevant apis/methods/fields would be enough.

Hmm that is a definite possibility. I will give that a try thanks :slight_smile:

Yes that was exactly what I was missing. They are showing up now. You are a life saver! The imported geo is still quite wonky but it at least resembles what it should and now that I can see it it will be a lot easier to fix and improve the code.

[EDIT: I have obtained the necessary tools to generate appropriate FBX files for the SDK/Unreal. The Unreal FBX import GUI can import around 500 meshes at a time, depending on their file name length. This appears to be a prototypical Windows API limitation (multiple file selection). I imagine there would be a way to programmatically execute the SDK, to work around this limitation].

Dear Lemmy101/Epic - can you please provide access to the code that was removed from this thread (eg via github)?

My use case is as follows;

  1. I have 10000 unique meshes that I wish to import into the Unreal Editor as static meshes.
  2. I don’t own any FBX tools, and none of its features are necessary (all I need to replicate is the geometry of my existing files as Unreal static meshes). If the Unreal Editor allowed the definition of static meshes directly via c++ function calls, then I wouldn’t be using the FBX pipeline/SDK.
  3. I find coding much simpler than (in my context) unnecessarily comprehensive graphical user interfaces.
  4. I don’t wish to have to replicate any GUI procedure multiple times (in case the geometry of my mesh library changes during development).
  5. I could generate procedural meshes dynamically at runtime (ProceduralMeshComponent), but I have performance concerns (and don’t wish to risk this path unless absolutely necessary).
  6. For optimisation purposes, I need to be very specific about the details of my meshes (and not rely on materials that have passed through multiple black box pipelines). All of the mesh properties I require to generate are available within the ProceduralMeshComponent library.
  7. I wish to perform actor specification at the same time as mesh generation (via code).

My first editing experience with UEdit was 15+ years ago, and I am looking forward to obtaining a solution on generating these static meshes. Thanks again for releasing this great engine (I expect it to scale very well).