RemoveInstance() Assertion fails on UHierarchialInstancedStaticMeshComponent

Consistently get an Assertion failure attempting to remove an Instance from a UHierchialInstancedStaticMesh

Unknown exception - code 00000001 (first/second  not available)

"Assertion failed: !RigidActorSync [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.9\Engine\Source\Runtime\Engine\Private\PhysicsEngine\BodyInstance.cpp] [Line

UE4Editor_Core!FDebug::AssertFailed() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\core\private\misc\outputdevice.cpp:354]
UE4Editor_Engine!FBodyInstance::CopyBodyInstancePropertiesFrom() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\engine\private\physicsengine\bodyinstance.cpp:2854]
UE4Editor_Engine!UInstancedStaticMeshComponent::InitInstanceBody() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\engine\private\instancedstaticmesh.cpp:962]
UE4Editor_Engine!UHierarchicalInstancedStaticMeshComponent::RemoveInstanceInternal() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\engine\private\hierarchicalinstancedstaticmesh.cpp:1652]
UE4Editor_Engine!UHierarchicalInstancedStaticMeshComponent::RemoveInstance() [d:\buildfarm\buildmachine_++depot+ue4-releases+4.9\engine\source\runtime\engine\private\hierarchicalinstancedstaticmesh.cpp:1691]

Looking at the GitHub code for RemoveInstanceInternal, there seems to be a number of problems there. For instance

		int32 LastInstanceIndex = PerInstanceSMData.Num();

Is out of bounds. Did you mean?

		int32 LastInstanceIndex = PerInstanceSMData.Num() -1;

But that’s not all that’s wrong here. After duping the code and attempting to fix myself I get other errors too. My suspicion is it’s a sync issue with the various different arrays and the RemovedInstance array.

Hey Xilverback-

Could you post the logs from the crash as well? Also, what source file is the line of code you posted from? Does the crash occur in a new project without any additional content? Can you provide details on how you’re setting up and using the UHierchialInstancedStaticMesh to help me reproduce the crash on my end?

Cheers

The bug starts in UHierarchicalInstancedStaticMeshComponent::RemoveInstanceInternal()

That’s in UnrealEngine/Engine/Source/Runtime/Engine/Private/HierarchicalInstancedStaticMesh.cpp

I’ll see if I have the old crash logs. Recreating all this in a new project is going to be a headache for either of us. I’m spawning an actor that has the HierarchialInstanceStaticMeshComponent that randomly generates instances of the components on runtime. I’ve modified the Actor’s TakeDamage function to remove the hit component. That’s where the trouble starts.

Attached is the CrashLogs. I had to recreate the problem, since I’ve got a cludged workaround.CrashLogs

Hi Xilverback,

I tried to reproduce the issue that you described, but was unsuccessful. I first created an Actor Blueprint and added a HierarchicalInstancedStaticMesh component to it. I assigned a static mesh, then added 6 instances of the mesh and spaced them out so they were each visible. Then I set up the Blueprint so that it would call RemoveInstance when I pressed a key and it worked without any problems.

I then made a new code class actor and added a HierarchicalInstancedStaticMesh component. I also added a function in the class that would call RemoveInstance. I made a Blueprint of the new code class, then set a static mesh and added several instances, spaced out to make each one visible. I then set the Blueprint to call the code function I added on a keypress, and that also worked without any problems.

Would it be possible to get some more information regarding how you are setting up your HierarchicalInstancedStaticMesh component and how you are going about calling RemoveInstance?

Well, thanks for looking into it. I’ll see if I can get to it this weekend. I’ve worked around it by writing my own RemoveInstanceInternal function. If It helps, I’m testing with a Dedicated Server. Yesterday, I tested and it took 3 attempts before the crash.

Hello XIlverback, did you have any to look into this over the weekend? I just picked up this issue so I’ll be trying to reproduce on my end but I’d also be interested to know what you’ve found thus far.

From what I can tell, it looks like the assertion comes into play when a removal occurs during an async rebuild of the tree. I switched to a technique that avoids the need for multiple async rebuilds and haven’t seen the problem pop back up.

I see, I’m glad to hear that you found the problem and know a way to avoid it. Please let us know if you have this issue crop up again and we’ll be happy to help. Until then, I’ve converted that comment into an answer and I’ll leave that as the accepted one.