Converting an FProceduralMeshSection to a UStaticMesh at runtime in a packaged shipping build

Hello,
I am currently trying to build a tool part of which requires that an FBX file be loaded at runtime and used in the game as a UStaticMeshComponent. I can do this quite easily with the editor by using the RuntimeFBXImport plugin and then converting the resulting UProceduralMeshComponent into a UStaticMeshComponent with the SourceModels variable that is in the UStaticMesh. However, this is behind a “#if WITH_EDITORONLY_DATA”, so I can’t access this or other necessary functionality when I try to package the project. Would it be feasible to change this variable and a few other things in the engine so that I can use them even when packaged? Or is there a better way to create a UStaticMesh from a UProceduralMeshComponent? Any help would be greatly appreciated.
The method I am using to convert between procedural and static is here: https://answers.unrealengine.com/que…h-problem.html
I am using UE4.22.3
Thank you

1 Like

FMeshDescription is I think the most up-to-date way to define meshes, and I believe it’s not restricted to editor only. Look into UStaticMesh::BuildFromStaticMeshDescriptions.

That is exactly what I need, but now I am running into an issue where it mysteriously crashed when run outside of the editor? Here’s the code I’m using:



static const FMeshDescription description = BuildMeshDescription(NewMesh);
TArray<const FMeshDescription*> descs;
descs.Add( &description );

class UStaticMesh* NewStaticMesh = NewObject<UStaticMesh>();
NewStaticMesh->AddMaterial(NewMesh->GetMaterial(0));
NewStaticMesh->BuildFromMeshDescriptions(descs);

SetStaticMesh(NewStaticMesh);


“NewMesh” is a UProceduralMeshComponent that only has one mesh section. Am I missing some initialization step? When it crashes, it gives me no information at all about the problem, despite running perfectly in the editor.

Edit:
Callstack:



NDDS-Win64-DebugGame.exe!UStaticMesh::GetUVChannelData(int)
NDDS-Win64-DebugGame.exe!UStaticMeshComponent::GetMaterialStreamingData(int,struct FPrimitiveMaterialInfo &)
NDDS-Win64-DebugGame.exe!UMeshComponent::GetStreamingTextureInfoInner(class FStreamingTextureLevelContext &,class TArray<struct FStreamingTextureBuildInfo,class TSizedDefaultAllocator<32> > const *,float,class TArray<struct FStreamingRenderAssetPrimitiveInfo,class TSizedDefaultAllocator<32> > &)
NDDS-Win64-DebugGame.exe!UStaticMeshComponent::GetStreamingRenderAssetInfo(class FStreamingTextureLevelContext &,class TArray<struct FStreamingRenderAssetPrimitiveInfo,class TSizedDefaultAllocator<32> > &)
NDDS-Win64-DebugGame.exe!UPrimitiveComponent::GetStreamingRenderAssetInfoWithNULLRemoval(class FStreamingTextureLevelContext &,class TArray<struct FStreamingRenderAssetPrimitiveInfo,class TSizedDefaultAllocator<32> > &)
NDDS-Win64-DebugGame.exe!FRenderAssetInstanceState::AddComponentIgnoreBounds(class UPrimitiveComponent const *,class FStreamingTextureLevelContext &)
NDDS-Win64-DebugGame.exe!FDynamicRenderAssetInstanceManager::IncrementalUpdate(class TArray<class UStreamableRenderAsset const *,class TInlineAllocator<12,class TSizedDefaultAllocator<32> > > &,float)
NDDS-Win64-DebugGame.exe!FRenderAssetStreamingManager::IncrementalUpdate(float,bool)
NDDS-Win64-DebugGame.exe!FRenderAssetStreamingManager::UpdateResourceStreaming(float,bool)
NDDS-Win64-DebugGame.exe!FStreamingManagerCollection::UpdateResourceStreaming(float,bool)
NDDS-Win64-DebugGame.exe!FStreamingManagerCollection::Tick(float,bool)
NDDS-Win64-DebugGame.exe!UGameEngine::Tick(float,bool)
NDDS-Win64-DebugGame.exe!FEngineLoop::Tick(void)
NDDS-Win64-DebugGame.exe!GuardedMain(wchar_t const *,struct HINSTANCE__ *,struct HINSTANCE__ *,int)
NDDS-Win64-DebugGame.exe!WinMain()
> [Inline Frame] NDDS-Win64-DebugGame.exe!invoke_main() Line 102
NDDS-Win64-DebugGame.exe!__scrt_common_main_seh() Line 288
kernel32.dll!00007ffd4c4a7bd4()
ntdll.dll!00007ffd4dface51()