Cannot save & cook UStaticMesh uasset files?

I’m importing and writing UStaticMesh files to uassets in the editor, which works fine at first glance - the files can be placed in maps and blueprints, can be tweaked with the StaticMesh editor and can even be exported to FBX.

However, when the time comes to cook them, suddenly, they’re all throwing up “Display: No exports found (or all exports are editor-only) for paintalpha_test_singlemesh_2. Package will not be saved.” errors and the like, and I can’t for the life of me figure out why.

They’re not specifically set as editor only as far as I can see, and the way they get saved should make them exactly the same as every other file that UE does want to package.

		UPackage* Package = CreatePackage(NULL, *NewPackageName);
		UStaticMesh* NewAsset = CreateStaticMesh(rawMesh, meshMaterials, Package, FName(*MeshName));
		FString PackageFileName = FPackageName::LongPackageNameToFilename(NewPackageName, FPackageName::GetAssetPackageExtension());
		if (UPackage::SavePackage(Package, NewAsset, RF_Public | RF_Standalone, *PackageFileName, GError, nullptr, false, true, SAVE_NoError))

Possibly related is that you can delete the saved uasset files in UE in the session you’ve saved them in, but if you try to delete them the next time you run UE, it crashes, unless you’ve opened them in the StaticMesh Editor again, then it wants to delete them without complaints.

Edit: did some more digging, and found even weirder things. If you rightclick-re-save the uasset files in the unreal editor, it turns them into 1K empty files for no apparent reason that I can see. Mesh is still loaded in memory, clicking on the file still opens it in the Static Mesh Editor, just… everything in the file is gone, and will mess up the data next time you restart the editor. Why?


  • Can you clarify what you mean when you say that you are “writing UStaticMesh files to UAssets”?
  • Where are you importing the static meshes from?
  • Is the code snippet you provided your own code or engine code, and where is the code coming from (class and/or function)?
  • Could you provide some sample assets?

The code snippet above (which is cobbled together from engine code, mostly) is part of the function that actually converts and saves mesh data in a format UE can use after it is generated based on the imported map file data (in a format that isn’t supported by default).
It saves the mesh to a package, which generates the appropriate .uasset file in the Contents directory.

A few sample outputs (with default worldgrid material) attached. As you can see, they import fine and you can use them in maps, you just… can’t ever click save or cook the project, for some reason.

I am still having some trouble understanding exactly why you are converting the UStaticMeshes to UAssets. We need to know specifically what it is you are trying to do, and get examples of the exact code that you are using when you are attempting to do it. Making changes to engine source code is not recommended, as it can often cause a multitude of issues. If you can show us how you are doing this, we can potentially see what the issue is.

Looks like I might not have expressed myself clearly enough, so I’ll try again, from the top.

I’m writing a plugin that imports 3D map data from a file format that’s not supported by default. The importing part and generating a collection of UStaticMeshes based on the data works without any problems, and I have not changed the engine source code in any way, just used it as a model for my own code. (The CreateStaticMesh on line 2 is the one from StaticMeshEdit.cpp, for example)

However, I can’t just spawn an AStaticMeshActor with an UStaticMesh assigned to it into a scene and call it a day, because
a) I want the user to be able to adjust and edit/replace the meshes easily, which they can’t do if they have to click each one in the world outliner and then doubleclick it to open the mesh in the static mesh editor
b) it won’t cook anyway since the cooker can’t find the file for the UStaticMesh (as evidenced in this log snippet)

[2015.12.08-20.55.14:101][683]MainFrameActions: Cooking (Windows): UE4Editor-Cmd: [2015.12.08-20.55.14:096][  0]LogLinker:Warning: Can't find file '/Game/ballsub/Meshes/ballsub_singlemesh_2'

[2015.12.08-20.55.14:102][683]MainFrameActions: Cooking (Windows): UE4Editor-Cmd: [2015.12.08-20.55.14:096][  0]LogUObjectGlobals:Warning: Failed to load '/Game/ballsub/Meshes/ballsub_singlemesh_2': Can't find file '/Game/ballsub/Meshes/ballsub_singlemesh_2'

[2015.12.08-20.55.14:102][683]MainFrameActions: Cooking (Windows): UE4Editor-Cmd: [2015.12.08-20.55.14:098][  0]LogLinker:Warning: Can't find file for asset '/Game/ballsub/Meshes/ballsub_singlemesh_2' while loading ../../../../../../Unreal/Projects/HammUEr10/Content/ballmap.umap.

So, I need to actually specifically save the UStaticMeshes somewhere so the engine will be able to find them later and the user can do whatever they want with them.

(continued, since I ran over the max character limit)


Hence, after creating the UStaticMesh, I try to save it to an UPackage with the code on lines 6 and 7 in the original post. (I have also tried versions with GEditor->SavePackage and with different RF_ flags, all to no avail) This creates a .uasset file in the correct directory that also shows up in the Content Browser as expected and, when opened in a hex editor, shows the seemingly correct serialized UStaticMesh data. You can open them in the static mesh editor inside of UE and everything looks okay.

However, unexpectedly, if you save them (either by right-clicking the asset in the content browser or from the menu in the static mesh editor) even if you didn’t actually change anything, the data in the file gets wiped and replaced with basically an empty serialization that only contains the UE build version.

And of course, the files also won’t cook, giving errors like these

[2015.12.08-20.55.13:875][673]MainFrameActions: Cooking (Windows): UE4Editor-Cmd: [2015.12.08-20.55.13:860][  0]LogSavePackage:Display: No exports found (or all exports are editor-only) for zepdockmaybe10_groupmesh_22829. Package will not be saved.

I’m basically asking how I’m supposed to actually correctly save/store my UStaticMeshes (and other base formats like UTexture2D and UMaterial, for example) so none of the weirdness happens and the files can be cooked normally.

Hope that clears up any misunderstandings.

I’m almost positive it’s something to do with the SavePackage call, be it UPackage or GEditor flavour.

Also, even turning the SAVE_NoError into SAVE_None so it doesn’t not generate errors on save just makes the SavePackage calls return true, so… I don’t know.
(It also doesn’t help that pretty much everything I can find on the forum/answerhub is people apparently using pretty much exactly the same code to save their data with no trouble at all.)

I’m kinda just bumping this to indicate that more than one person needs this fixed (albeit just because I have a reliance on Turfster’s plugin).

Maybe it’s worthwhile elaborating on the context by linking the plugin but maybe not, since we now find that this is happening seemingly any time Turfs tries to save any type of asset via code, not just Staticmeshes.

Could anyone at least tell us what “No exports found (or all exports are editor-only)” means/would normally mean, and in what circumstances an “export” would normally be marked “editor-only”?

So… I was wrong.
It wasn’t in the SavePackage call, it was in the CreateStaticMesh copy I made (seriously, tracking down why external symbols don’t resolve even if you’ve included the header file that contains the definition can be a total pain, so much so that it’s sometimes easier to just copy the code if it doesn’t rely on too much extra stuff).

I’d commented out the RecreateRenderStateContext line in it (another external symbol that didn’t resolve, but that I finally tracked down today. The answer is: needed a RenderCore dependency next to the Engine one listed in the API).

Uncommented that and voila, files get saved fine and can be cooked.