How is saving uassets in a plugin supposed to work, really?

I’ve run into a rather critical roadblock with my plugin, and I have no idea what Unreal is doing or why, so I’m hoping someone can help me out with this.

I’m importing 3D data, converting it to a static mesh and saving it to uasset files for reuse with the following code… or so I thought.

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))
    // put the actor in the scene here

This puts the mesh in the scene and creates the relevant uasset file - containing the serialised UStaticMesh data - in the right directory.
So far, so good.

However, when trying to cook the project, I get nothing but “No exports found (or all exports are editor-only) for <assetname>” errors. Even weirder, if you right-click the asset file in the content browser and save it, the editor replaces the perfectly fine uasset file with a 1K “empty” one (which basically just contains the UE version number that ‘saved’ it)… And to further compound the weirdness, if you decide you don’t want the files and want to delete them, you can do this fine during the same session they were written in. If, however, it’s a new session, trying to delete the assets will crash the editor, unless you opened an asset in the static mesh editor during that session/opened a map file that contains the meshes, after which you can delete them just fine.

I’ve been trying all kinds of things to fix it, approaching it from various angles, but this behaviour is frankly so utterly bizarre that I’m at my wits’ end.
Anyone have an idea of what I’m doing wrong or why this is happening?

(Answerhub version of this question)

Blump. 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”?

Aaand I tracked it down.
It was a commented out RecreateRenderStateContext that messed everything up, somehow?
(If you have one and you’re wondering why it gives unresolved external errors, you need RenderCore in your dependencies)