BatchUpdateInstancesTransforms causing stuttering with large amounts of instances

Hi, im having a stuttering problem in UE4 at runtime. Every 5-30 seconds itl hang for anywhere from 1 second upto 20 seconds, or about 30ms upto and over 3000ms, and then continue, im instancing 10000 units which are made of 5 parts each for a total of 50000 objects and 5 HierarchicalInstancedMesh components im updating the instanced positions every frame. This results in getting around 50 fps which is just being gpu bottle necked atm, should be easily able to increase this further and atm no use of LOD’s, the tanks total about 15k tris each. Ive profiled my code and ive narrowed it down purely to 1 line, The BatchUpdateInstancesTransforms, it works perfectly fine except for the stuttering issue and that line is causing it, any help would be appreciated as i have no idea where to start on how to solve this, Also this issue appears when there are less objects even down to just 1000 units it still persists just not as violent but will be unplayable with the stuttering either way. The problem completely disappears if i disable the function so i know it is definitely this function that’s causing it. Also my Ram usage skyrockets when that line is active so im wondering if its to do with my memory usage. Thankyou for any help.
BatchUpdateInstancesTransforms causing stuttering with large amounts of instances. - YouTube Heres a video of the issue.
When i dont use BatchUpdateInstancesTransforms the Ram usage stays around 10gb and no stuttering occurs, its only when i use BatchUpdateInstancesTransforms that these problems arise.

Are your HISMs marked with VisibleAnywhere or EditAnywhere, so you could see their content in Editor? Large visible arrays in the editor tend to use a huge amount of ram.

Nope they arnt, the stuttering issue seems to disappear if i actually give new locations for each mesh to be in rather than just moving them to the location they already are, i have a feeling it could be some bug with hierarchical instance meshes, so im likey going to try only update the meshes when i need to move them instead

That seems to be better. Because as I understand BatchUpdateInstancesTransforms does a complete for loop of its own to update every instance which I don’t think is very helpful. Updating only the instances that need to and then call MarkRenderStateDirty at the end seems to be more performant. BatchUpdateInstancesTransforms however has a huge difference in blueprint though.

If you suspect a bug, have you tried changing to ISM? I worked with the new PerInstanceCustomData and I notices it’s not compatible with HISM, but works perfectly with ISM.

The only set back with not using BatchUpdate is that PartialNavigationUpdate() gets called for every instance in UpdateInstanceTransform() which is somewhat futile, as it needs to get called just once for every instance.

1 Like

This is precisely because you’re using a Hierarchical Static Mesh. What’s the reason for it being Hierarchical vs. regular Instanced Mesh?

Hierarchical static meshes were never designed to be moved per-frame. If you do need to move them manually, create an array (don’t recreate it per-tick either) and update manually through it.

I don’t think it was meant to be never moved. Why would they put Update methods then? And by being hierarchical, I think they meant it supports LOD for instances which ISM does not support.