# What is a good approach to update and replace large numbers of instances in game?

**URL:** <https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206>\
**Category:** World Creation\
**Tags:** Hierarchical-Instanced-Static-Mesh, unreal-engine, Foliage, instances, question\
**Created:** [May 28, 2023, 12:14pm UTC](https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206 "2023-05-28T12:14:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SimenMusaeus](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@SimenMusaeus](https://forums.unrealengine.com/u/SimenMusaeus)\
**Post date:** [May 28, 2023, 12:14pm UTC](https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206/1 "2023-05-28T12:14:48Z")

</div>

What is a good approach to update and replace large numbers of instances in game?

As for example in a farm simulator, how could you animate the scale as the plants grows, then replace the mesh when the plants are harvested, or remove a plant when it dies? Say it should be on a field of 200 x 200 rows, so 40k instances.

I’m not planing to do a farm simulator, but I’m looking for suggestion for how to handle updates on large amounts of instances. The foliage system seems to be designed for static plants and trees. The same goes for packed level instances, which seems designed for identical copies. I’ve also looked into Instanced Static Meshes, but it seems that updating their transforms or custom data quickly leads to performance hits.

So looking for technical ideas on how to approach this problem?

---

<div class="post-metadata">

**Author:** ![3dRaven](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/3draven/32/906552_2.png) [@3dRaven](https://forums.unrealengine.com/u/3dRaven)\
**Post date:** [May 28, 2023, 1:54pm UTC](https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206/2 "2023-05-28T13:54:22Z")

</div>

You could do normal plants, hierarchical instanced static meshes or instanced static meshes and do the animation on a material level (using the time and sine node / Simple grass wind based on vertex color)

[![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/e/6/8e691fef7163652108ceb4e448707bb04a19b1d1.jpeg "Simple Global Wind in UE4 (One weird trick! Everyone hates him!)") ](https://www.youtube.com/watch?v=27Gr2RRhtNM)

You can also feed in per instance parameters to a plant with “PerInstanceCustomData”, Color and other parameters you would use to change it on a shader level.

You could also look into the new procedural tools (“PCG” Procedural Content Generation plugin). Though I’m not sure how they are performance wise, with runtime updates.

---

<div class="post-metadata">

**Author:** ![RecourseDesign](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/recoursedesign/32/1194503_2.png) [@RecourseDesign](https://forums.unrealengine.com/u/RecourseDesign)\
**Post date:** [May 28, 2023, 5:17pm UTC](https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206/3 "2023-05-28T17:17:22Z")

</div>

Maybe, rather than update all 40k at once, stagger it out over multiple frames - I built a stagger system for something else (Distributed Transactions) and it works really well, there’s a video at the bottom of this page:

> **[rdInst Tutorial 16 - Recourse Design ltd.](https://recourse.nz/index.php/rdInst-tutorial-16/)**
>
> rdInst Tutorial 16 – Adding Instances using Distributed Transactions Last Updated: 2nd February 2023 If you’re wanting to add a lot of Static Mesh Instances to your level during run time, but you don’t want the game to slow down or jitter, you can...

---

<div class="post-metadata">

**Author:** ![MostHost\_LA](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/mosthost_la/32/907035_2.png) [@MostHost\_LA](https://forums.unrealengine.com/u/MostHost_LA)\
**Post date:** [May 28, 2023, 8:50pm UTC](https://forums.unrealengine.com/t/what-is-a-good-approach-to-update-and-replace-large-numbers-of-instances-in-game/1181206/4 "2023-05-28T20:50:35Z")

</div>

Async batches of sub 500 units will work OK if they are _off_ the game thread.

You need to specificlally look at creating your own thread, your own async function, and how to have it interact with foliage.

However if you needed to build a real system for a game, you probably wouldnt bother and just use the shader material.  
As the first post mentions.

The part thats missing is the fact that you can manipulate the shader and mesh to do crazy things, like a proper growth cycle, mesh replacements, mesh additions, and a bunch more just by playing with the material and different UV channels.

The plants collision _will not_ be updated this way.

So for instance, planting trees and going from seed to sapling to tree will require an actual mesh update to deal with the collision as well…
