I recently implemented a blueprint system for replace instanced foliage with a physical skeletal mesh when the player is near, and then swaps back to the instanced foliage once the player moves away. It was thanks to a series from Jonas Molgaard.
Basically, there’s a collision sphere that moves with the player and whenever the foliage is overlapped by the sphere, it is replaced with a physics asset so it interacts with the player, and then it reverts back after the player moves away.
However, I’m running into problems with performance. Everything behaves and works well up until the foliage surpasses a certain amount of instances. It seems to be getting CPU bottle necked when it is replacing even just 1 instance of foliage. I’m assuming this is because its querying the entire foliage actor and checking all of them, so the larger the number of instances the more it queries. This recording shows the drop in performance when the instance count gets higher. (keep in mind the number of physical skeletal meshes is the same, just more foliage instances)
I’ve also got a pastebin to show the blueprint that is running the replacement code:
Does anyone know of a more optimized method for looking up and replacing foliage instanced meshes? Or any other suggestions for how to optimize this.