Assign unique dynamic material for every single foliage instance and modify them independently at runtime.

I have shrine in my levels and I want them to turn all grass around them darker.
To do that, I retrieve all foliages actors, I use for each and branch to only “select” grass.
Then I use another loop and branch to only affect the grass that are within range of the shrine actor.
For the instances within range, I check if they use a dynamic material instance, if they don’t I create it.
Then I modify the dynamic material instance to make it darker.

But when I do that, nothing happens for a while, then at some point, all my grass becomes darker.
I suppose UE make all instances of a foliage type to share the same material for performance reason.

So here are my questions :
How do I ensure that each grass mesh has its own individual material instance?
Is it even stupid to try to do that or will my computer melt once I have 20k dynamic material instances?

Hi. You can’t - you’re right that all instances use the same material.

You could create either a texture premade with the areas of the map you want dark - or create a RenderTarget at runtime and then read that from the material and apply darkness to the areas of the texture that you’ve painted.

Another way is to use per-instance custom data and mark the instances around the area by setting the PIC to 1 - but this can add overhead if you’re changing them at runtime.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.