How to remove specific HISM if colliding?

Hey all I’ve made a spawner BP that will randomly populate the level with actors. I save the transform of the actors then compare it to the next one with some subtraction figure out how much space is between them if the number is elss then the allowed amount it should destroy the new instance.

For some reason remove instance won’t work, neither the destroy component.

I need a way to remove the HISM after it is spawned if it is colliding with another mesh.

Any help appreciated.

So there are a few things to consider when you are handling HISM Components. First off, if this is a multiplayer game know that HISM data does not replicate, the component does but the actual instance data does not replicate. You need to build a system for replicating an array of data you need to clients. Literally for multiplayer games I destroy the HISM data completely on clients and rebuild it from a secondary replicated array of data (just be careful about minding array replication size limits). Further more you need to make sure that the system handles late joins and does not just rely upon Network Multicasting (this is a mistake I see constantly on the market place). Generally I override the HISM component itself in C++, create some custom Add/Remove functions, and use a RepNotify on my custom data array to clear then rebuild the HISM data on clients when the array updates. You can improve performance by using the Fast Array Replication System that Way Too few developers know about.

with that out of the way it is really a matter of make sure you have “UseDynamicInstanceBuffer” and “KeepInstanceBufferCPUAccess” set to true. Now you should be able to add and remove instances dynamically.

1 Like

Should I rebuild my BP to do the replication or is that an “easy” fix I can edit in later?

What I’m trying to do is get an exact ref to a specific HISM Instance(created at runtime in the world) and destroy it if it’s location is overlapping another one.

Here’s my attempt. The remove instance node doesn’t work in this situation.

There should be a function called “RemoveInstance” which takes a int32 index value, so you’ll have to keep / find what index you want to remove. Here is the kicker though, Instance Static Mesh Components remove by performing a swap of the last index with the index you are removing, it does this to reduce the cost of resizing the array, so if you are trying to keep a record of these indexes in a secondary array you’ll have to perform the same sort of swap and remove on it, Luckly this is a built in function of TArrays.

Honestly if you are building a Multiplayer game do not try to bolt on replication and RPCs later, especially when trying to deal with a fairly complicated system like ISM’s and HISMs. For your own sanity think multiplayer first if you are building multiplayer, don’t skimp on this or you have a very high chance of regretting it later.

Also I noticed you are using “VectorLength” up there. This is fine for proof of concept but know that the square root function is one of the most expensive operations in computing. If this is happening on tick I highly suggest switching to “VectorLengthSquared” which gives you the vector length with out square rooting it. For your “Min Safe Spawn Distance” comparison you just square the distance value you want to hit so if you want minimum 10 centimeters you use 100, 50cm you use 2500.

I may have figured out part of the issue. For some reason my array is only allowing a get copy not get ref. So any changes aren’t propagated back to the array.

I went ahead and swapped out my vector length as well, this is all just hooked up to the beginplay just runs once.

Would you happen to know where the UseDynamicInstanceBuffer" and “KeepInstanceBufferCPUAccess” settings are located at?

Thanks for your help thus far.

Those two settings should be part of the HISM component itself, granted it’s been a few versions since I’ve messed with ISMs and HISMs but I doubt it has changed that much. I am fairly sure they are exposed to BP as well, they may have a slightly different name though, epic loves to tweak the naming of things for BP.

Were you able to find these settings?

Yeah for bulk removals you need to remove instance in reverse sort order. Did this for foliage tool mass removals/replacements.

You can accumulate instances in a Set and then batch-remove them:

Super efficient. This also gives you access to Difference, Intersection and Union operations.

Will the instance index of the unremoved Instances, get reshuffled in the HISM?

I ended up having to write a custom reverse for each loop function and what I did was remove the instances then you get the index and also remove it from the array, since it is in reverse the index being removed will not effect the array being shrunk.

Will the instance index of the
unremoved Instances, get reshuffled in
the HISM?

Yes. The indexes are always from 0-Last. Since there’s fewer of them after removal, the indexes will shift.

  • before:

  • after:


I ended up having to write a custom
reverse for each loop function

Depending on the requirement that may or may not be necessary, one can just:

The abovementioned Sets work flawlessly for this as they hold unique indexes only. Keep accumulating indexes in a set and remove all in one go when you’re ready.

I wrote a function that would sort the indexes in descending order and output the order array on return. That fed a loop.

I was mass replacing painted foliage with a custom HISM instances from a class.

this works very well for bulk removals. If you have to replace/swap out, then reverse order looping is the way to go.