The editor crashes trying to access an out of bounds array index from the hierarchical instanced static mesh component.
Steps to reproduce:
- Create a c++ class inheriting from the actor class
- Add a UPROPERTY(EditAnywhere, BlueprintReadWrite) UHierarchicalInstancedStaticMeshComponent* InstancedStaticMesh
- Add a UPROPERTY(EditAnywhere, BlueprintReadWrite) float InstanceCount
- Use CreateDefaultSubobject to create the hierarchical instanced static mesh component
- Add the function OnConstruction(const FTransform& Transform)
- 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).
- Create a blueprint inheriting from the c++ class
- Assign a mesh and material in the details panel for the hierarchical instanced static mesh component
- Change InstanceCount to 1
- Save and compile the blueprint, it should work the first time
- Change the InstanceCount to 2. The blueprint viewport should update showing a second instance added
- Save, then try to recompile the blueprint and it should crash
- 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
- Change InstanceCount to 3, 4, 5, 6, notice every time the blueprint viewport updates accordingly
- 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:
- Create a c++ class with a UInstancedStaticMeshComponent
- Create a blueprint inheriting from this class
- Change the UInstancedStaticMeshComponent to UHierarchicalInstancedStaticMeshComponent
- Try to compile with a hot reload in the editor and it should crash
- Build the solution in visual studio
- 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.