Hierarchical instanced static mesh component Bugg

Hi, i think i’ve found a bugg with this component when you try to remove the 0 in its array.

I was making a Trail to follow an object, then i wanted to remove the trail starting from 0 in its array. It worked for the first field, but after it “removed” it, it replaced the 0, with the value that the last index in the array had.
In other words, instead of 0 becoming what 1 was in the array, 0 became what the last value had.
I checked it carefully frame by frame, it was quite puzzling. Then i redid the exact same thing but with instanced static meshes and it worked as it should.

I tried to redo this bugg in a clean project, but this time when i tried to remove the 0, i got an engine crash everytime.
Here’s the project i redid it in, you add instances with T and Remove with R. Associated blueprints are in content browser root folder.

https://drive.google.com/file/d/0B-hVYtzySBWTaVNJVGtNRzhuYVk/view?usp=sharing

All the best!

Hello nameLive,

Thank you for reporting this issue. I’m currently looking into it using the project you provided but I wanted to let you know why the project was crashing. When you went to populate the array, the Hierarchical Instanced Static Mesh didn’t have a Static Mesh set, so it was essentially creating blank instances. When the remove function tried to access them, it saw an empty array and crashed. Setting a static mesh fixes this.

I’ve reproduced the problem that you reported using your project and it definitely does seem like a bug. I’ve placed a report in which you can find here: UE-40693 You can track the bug’s progress there as well.

Have a nice day!

Not only has HISM this ordering bug but ISM does not correctly remove instances all the time.
I am currently using ISM and waiting for the fix in 4.18 for them.
But I need HISM for per-instance LOD. Otherwise I won’t have any chance for near-distance geometry details. When will this bug be fixed? It’s crucial for performance on visually appealing instances.

Can’t this be done in the context of the ISM bug?

Bump this also, Id like a fix please, and have seen it on as UE-40693 but its been around for ages.

Thanks,
Ben.

I ran into this issue as well, and I’ve come to the conclusion that this is not in fact a bug, but is in reality a lack of proper documentation for the HISMC RemoveInstance() method.

What’s happening is that internally, the HISMC array is removing the instance using TArray.RemoveAtSwap(int32 index). This is an array removal operation that indeed removes the array item at index, then replaces it with the item that is at the end of the array: TArray::RemoveAtSwap | Unreal Engine Documentation

RemoveAtSwap() is far more efficient than RemoveAt(), which is probably why it was used.

One way to work with this is to store your reference data for the HISMC instances in a TArray, and simply use RemoveAtSwap() to remove your data in your array, to mirror the state of the HISMC internal array.

Cheers. :slight_smile:

I don’t think this is actually a bug, please see my answer below.

Hello Matthew,

I do not believe this is a bug, please see my answer below. In fact, if this “bug” were to be fixed, and HISMC instance arrays to switch to using RemoveAt() rather than RemoveAtSwap(), it would reduce the efficiency of not only the HISMC algorithms, but also of data structure algorithms that manage HISMC indices in game code! (e.g. only having to update the cached index of one instance, rather than ALL indices > the index that was removed!).

What should really be done are two things:

1. Update the UE API documentation for HISMC RemoveInstance() to indicate the array operation used behind the scenes (RemoveAtSwap) so that developers understand why the last element of the array is being placed into the hole in the array.

2. Update the UE API documentation for TArray RemoveAtSwap() to explain that it moves the last item in the array to fill the hole created by the remove operation.

This behavior of RemoveAtSwap() is detailed here in the UE blog: Optimizing TArray Usage for Performance - Unreal Engine

The blog article states:

“There’s a way to avoid the performance hit of shifting all elements to fill in a gap when an element is removed: RemoveAtSwap(). This removes the element at the requested index, then if possible replaces it with the last element in the array to fill in the hole, rather than shifting down all elements.”

Using RemoveAtSwap() is far more efficient than RemoveAt() (both internall in the engine, and within developer game code) !!! Please do not fix this “bug”!

Hello superdreamgen,

Thank you for pointing this out. I’m not now, nor was I ever, very familiar with HISM so I didn’t notice this but you’re correct. I’ll put a comment on the bug report that mentions that this shouldn’t exactly be “fixed” but an additional remove function for the functionality that the other posters were expecting would be useful.

Hello there Matthew,

If they do add a RemoveInstance function that doesn’t utilize RemoveAtSwap, the API doc should note that calling that function instead will lead to slightly reduced performance.