Dynamically assign materials in Construction Script

Creating a dynamic crowd system using Instanced Static Meshes and VATs (vertex animation textures).

To create variation I have made several variations in the crowd agent texture atlas Base Color.

Instead of duplicating the static mesh crowd agents in my Content Browser, and applying the new materials I was wondering if there was a way to randomly assign these new materials when the static mesh crowd agent is instanced in my Construction Script?

I am aware of the ‘PerInstanceRandom’ node which might help but not sure how materials would be applied.

How might this be done?

Depends on how your crowd is setup.
Is it a single set of characters, or are they seperate meshes?
Do you want individual color difference per character?
Or are these variations of the texture atlas per group?
Per instance can work on individual people.
You can create a world position x-y color texture.
You can use random stream(seed) for some texture variations.
In my own project i am heavily using random stream to set a seed per character,
that seed number then determines things like gender, skincolor, age, hair grooms etc.
But depending what kind of project your making that can be way too much.
If its just a crowd for the background and you already have multiple texture variations you could add those to an array and add random stream, then in construction script do something like “random integer in range from stream” with the max set to your array length. Then it will use to stream to pick one of the materials in the array.
Just an example :slight_smile: so many ways to do this, it all depends.