Just found a bug with HISM (hierarchical instanced static mesh) component and was finally able to setup reproduction steps. I’ve sent a bug report but I’m posting here in case anyone has a similar issue and might know a solution already.
The problem is that compiling Blueprint child of native class containing a private HISM component with transforms updated in OnConstruct crashes the editor.
#Reproduction steps
.
- Create a new C++ project.
- Add an Actor C++ class to it.
- Create HISMComponent as private UPROPERTY so that its instances are kept on Actor duplication with Alt+Drag. Add AllowPrivateAccess=“true” to the UPROPERTY meta tag.
- Override OnConstructor and add at least one instance to the HISM and update its transform.
- After compiling, in the editor create a Blueprint child of the created native class. Open it and click compile.
#Detailed description
A native actor with a private HISM component, even if adding instances and updating their transforms in OnConstruction, compile successfully, can be spawned in the level by dragging it from the content browser and can duplicated with Alt+Drag, keeping its instances. But if a child Blueprint of such actor is created, even though nothing is changed, we can’t even compile it without crashing the editor.
After several tests, it seems one or more of the instance data arrays in the HISM class (like InstanceReorderTable) is not correctly synchronized with the other arrays. Sometimes the crash is in a failed check inside AddInstance, where it checks if the next instance index is equal to InstanceReorderTable.Num(), which indicates that it has registered instances not accounted for by the rest of the code.
Same code worked on UE 4.19. Except that it didn’t need the AllowPrivateAccess meta tag in the component uproperty.
Here are project files with the code: http://files.rvillani.com/unreal/HISMBug.zip