Hello,
I am working on a crowd system using Instanced UStaticMesh instanced to speed up things when possible. My crowd is composed of instanced meshes of each character part, instanced as many times as instanced character count.
Since Unreal 5.1 and aysnchronous compiling of StaticMeshes I have an issue.
My Static Meshes are built dynamically in my main actor when a model SkeletalMesh is plugged via PostEditChangeChainProperty()
This involves a conversion from skeletalMesh sections to RawMeshes then StaticMeshes via MyStaticMesh = NewObject() and MyStaticMesh->AddSourceModel(). This code part is based on the the RawMesh conversion utility found in MeshUtilites.
Then these static meshes are added as UHierarchicalInstancedStaticMeshComponent to the main Actor, ready to accept instances.
The issue comes when I call AddInstance on the UHierarchicalInstancedStaticMeshComponent.
The inherited UInstancedStaticMeshComponent (non hierarchical) works properly, but when we arrive in the
UHierarchicalInstancedStaticMeshComponent specific code, there is a check on wether the UStaticMesh is compiling, which is still the case. The specific code of UHierarchicalInstancedStaticMeshComponent::AddInstance is not processed, and it fails silently as the index from UInstancedStaticMeshComponent (non Hierarchical) is returned valid.
At this time nothing seems wrong, but later on slome calls are made to update transforms of the static meshes, which issues edit commands on the FStaticMeshInstanceBuffer::UpdateFromCommandBuffer_RenderThread
It crashes as the FStaticMeshInstanceBuffer should have added instances in the UHierarchicalInstancedStaticMeshComponent::AddInstance but it did not, the index is invalid.
-
How can I force a synchronous compiling of the StaticMeshes, or make an active wait on it, to avoid them being ‘IsCompiling=true" when adding instances.
I tried adding a ConditionalSleep on !(MyStaticMesh->IsCompiling’)) after creating my StaticMesh in the gameThread, but it appears to generate deadlocks, probably preventing calls to render ? -
Would it be possible to patch this, such as the addInstance does not fail silently on UHierarchicalInstancedStaticMeshComponent when StaticMesh is compiling, and accept edits on transforms in the mean time ?
Thank you
Sebastien