'Update Instance Transform' / 'Remove Instance' == big performance hit even if used only on 1 instance

Repro steps:

  1. Have a Landscape (or anything else) with large amount of grass/foliage painted (around 500k to test it)
  2. In blueprint, get any instance of the foliage mesh component and (using ‘Update Instance Transform’ with ‘Mark Render State Dirty’ enabled to see the changed transform) update its transform, for example, every 0.1s for couple of seconds. It gets massive lag this way.
  3. I’ve tesed it with profiler and here is what causes the lag:
    101436-
    What happens? Maybe it updates every instance inside foliage mesh component, instead of just one?

When I have less foliage painted on landscape (but still dense & visible over all viewport), the lag is almost not noticeable. How to fix this? Or maybe is there some workaround?

Update: Same thing happens with ‘Remove Instance’ node!

Hi ,

The lag you are experiencing is something I would expect in this case. Foliage instances are all instances tied to one actor. When you move the transform of one instance, technically it has to destroy and recreate every foliage instance in the level, which would easily cause the lag you are seeing when dealing with 500,000+ instances. Once foliage is placed, it is not meant to be moved or edited at runtime, because when one instance is updated, the entire foliage actor, including every instance within the foliage actor, must then be updated. The functionality you are looking for is going to require a different system to implement outside of the foliage tool, as this is a limitation of the tool.

Thanks for the explanation! Maybe I’ll divide existing foliage components into chunks (multiple components) on Begin Play to minimize the lag… Or find some other workaround.

Hey man, I have same problem, you can tell me which solution you have find? Tk

Hey did you ever find a solution? I tried splitting it up into many different instances but the performance was about identical when removing the instance as it was when they were all in the same instance static mesh component.

Hey, there is no real solution for this, since it needs to re-draw every instance anyway. In my case I’ve divided my foliage into chunks, for example instead of hacing only one hierarchical static mesh component for entire scene, I’ve recreated it using 5 components. This way when updating an instance it won’t re-draw whole big component, but only one of the 5 smaller components.

That’s what I did but I get the same lag spikes whether I split it into 5 or even 100 smaller components. With 500 Instances each.

It almost seems like if I remove an instance on one it still redraws every instance in the scene.

Thats exactly what it seems to be doing, it redraws every instance in the scene regardless of the foliage type or component. Does anyone have a fix for this yet? seems like it should not behave this way.

I’m afraid that this is a limitation of the engine and nothing can be done except some workarounds with chunking (but that all depends on your project) - see the answer, I’ve also added comments about it under it.

I have encountered the same problem 4.20, does anyone know how to solve this problem? I added hundreds of thousands of plants, and when I fell one of them, the FPS dropped from 120 to 8.

Is there a way to solve this problem? Too many tree instances have good fps, but cutting down trees will cause FPS to drop lot by 1 second.

Has anyone found a way around this problem? I don’t understand why changing the instances of 1 static mesh component would would force the redrawing of other unrelated components.

Use multiple InstancedFoliageActor with more or less 5 thousand actors each or according to the requirements of your game