I have an actor with many attached StaticMeshActors. I want to modify the materials for all of them at runtime. I could get all the attached actors, and ForEach create a new Dynamic Material Instance, and modify that instance as desired. However, if I have 1500 meshes sharing 100 materials, I really only need to create 100 Dynamic Material Instances, not 1500.
I’d appreciate any advice on how to construct a Blueprint script that:
- Creates a map/hash/association that can associate dynamic instances to materials.
- ForEach of the attached actors, finds the material used.
- If there is not already a dynamic instance associated with the material, it
- creates a dynamic instance,
- customizes it,
- associates it in the map/hash,
- and sets the actor to use it
- If there is already a dynamic instance, sets the actor to use it
- If there is not already a dynamic instance associated with the material, it
Alternatively (less optimal, but maybe easier to author?) it could be:
- Find all the attached actors (1500 of them)
- Find the unique set of materials they use (100 of them)
- ForEach of the materials, create a Dynamic Material Instance with my own customizations.
- Store these in a map/hash from original material to dynamic instance.
- ForEach of the attached actors, replace the original material with the associated dynamic instance.