Hierarchical instanced static mesh component crashing when compiling blueprint

The editor crashes trying to access an out of bounds array index from the hierarchical instanced static mesh component.

Steps to reproduce:

  1. Create a c++ class inheriting from the actor class
  2. Add a UPROPERTY(EditAnywhere, BlueprintReadWrite) UHierarchicalInstancedStaticMeshComponent* InstancedStaticMesh
  3. Add a UPROPERTY(EditAnywhere, BlueprintReadWrite) float InstanceCount
  4. Use CreateDefaultSubobject to create the hierarchical instanced static mesh component
  5. Add the function OnConstruction(const FTransform& Transform)
  6. In the OnConstruction function, call InstancedStaticMesh->ClearInstances(), and then add a for loop from 0 to InstanceCount calling InstancedStaticMesh->AddInstance(FTransform()) every loop (maybe add a translation so instances won’t overlap).
  7. Create a blueprint inheriting from the c++ class
  8. Assign a mesh and material in the details panel for the hierarchical instanced static mesh component
  9. Change InstanceCount to 1
  10. Save and compile the blueprint, it should work the first time
  11. Change the InstanceCount to 2. The blueprint viewport should update showing a second instance added
  12. Save, then try to recompile the blueprint and it should crash
  13. If you relaunch the editor, you’ll notice the blueprint now has InstanceCount at 2 (because it was saved before the crash), and there are 2 instances
  14. Change InstanceCount to 3, 4, 5, 6, notice every time the blueprint viewport updates accordingly
  15. Try to compile and it’ll crash again

This doesn’t happen with normal instanced static meshes. Nor does it happen when adding instances in the blueprint Construction Script node. I don’t think it happened in 4.12 either, just 4.13.

Another bug that’s probably related to this issue:

  1. Create a c++ class with a UInstancedStaticMeshComponent
  2. Create a blueprint inheriting from this class
  3. Change the UInstancedStaticMeshComponent to UHierarchicalInstancedStaticMeshComponent
  4. Try to compile with a hot reload in the editor and it should crash
  5. Build the solution in visual studio
  6. The editor will fail to launch as long as the blueprint in step 2 exists

The only way to get the editor to launch again is to change it back to UInstancedStaticMeshComponent and rebuild. You can only change a UinstancedStaticMeshComponent in a c++ class to a UHierarchcialStaticMeshComponent if there is no blueprint that currently inherits from that class.

Hey vle07,

Thanks for the detailed report. I was able to reproduce the issue and have entered a issue report for it. You can follow it here:

https://issues.unrealengine.com/issue/UE-37316