When creating an C++ Actor with a Hierarchical Instanced Static mesh. when duplicating such an actor with mesh instances, the instances are not visible on the level. In this state, calling HISM component's "ClearInstances" method causes engine crash.
Note: The crash does not occur, when there are additional instances added to the duplicated ones before call to the "ClearInstances".
This creates a problem when spawning instances using either Construction Script or" OnConstruction" method, because if there is a need of re-creating instances ( e.g. a spawn pattern has changed and it has to be reflected immediately in the editor), there needs to be a call to the "ClearInstances" method, as, otherwise, the created instances will be added to the HISM component, ending with more instances (from previous pattern + current pattern) rather than with instances being re-created using new pattern only (as intended). Due to this, the call to "ClearInstances" is also being executed immediately when duplicating an actor placed in the level, which results in similar editor crash as described earlier. Again, there is no problem, even with such usage of Construction Script / "OnConstruction" method, when the component has been created in blueprint, rather than in C++, and such blueprint created components behaves safely.
Additional Note Reported by the user:
There is a problem with different behavior of Instanced Static Mesh Component (ISM) and Hierarchical Instanced Static Mesh Component (HISM), when they are created for actor with C++ and when they are created for actor within blueprint. Actors with the component created in blueprint (within the class defaults, using Add Component drop down) behaves correctly and does not cause any unexpected anomalies. For the other hand, the component created in C++ using "CreateDefaultSubObject" (using either direct function, or using FObjectInitializer object), causes many issues, which leads for problems, when placing actors on level when using duplication, and when providing mesh instancing mechanics using Construction Script (OnConstruction method in Code. The first issue, which affects both ISM component and its Hierarchical version is the problem with visibility of instanced meshes when duplicating actor which has the (H)ISM (either Hierarchical or non-hierarchical version) component which is being created in Code. When duplicating such actor (either using Ctrl+W shortcut, or holding Alt key and dragging actor's gizmo), the duplicated actor should be duplicated including it's mesh instances which have been added using component's "AddInstance" method. When the component is created in blueprint, the mesh instances are being duplicated correctly - they are both visible on the level in the editor viewport and in the component's instances array, provided they were added using mentioned component's method. However, when using actor which has the component created in the constructor, the duplicated mesh instances are not visible on the level in the viewport, but they are still present in the component's "Instances" array. Adding additional instances to the duplicated actor makes those invisible instances re-appear in the viewport and work further as intended.
Project has been included for convenience. To Reproduce the Crash.
Result: Editor Crash
Expected: There is no editor crash, and all created mesh instances are being removed, both in level and in HISM component's "Instances" array, as they are when performing the same actions on actor, that has HISM component created in blueprint rather than in C++.
Duplication Issue that was mentioned in Users Additional Note:
1. Drag and drop BP_CppIsmActor or BP_CppHismActor blueprint to any level.
2. Select placed actor and click "Do Spawn Instances" button in the details panel.
3. Duplicate placed actor and move it slightly away.
Result: Mesh instances for duplicated actor are not visible on the level in the editor viewport although they are present in component's "Instances" array.
Expected: Mesh instances for duplicated actor are visible on the level in the editor viewport, as they are when duplicating actor, that has (H)ISM component created in blueprint rather than in C++.
There's no existing public thread on this issue, so head over toAnswerHub just mention UE-75442 in the post.