creating dynamic material instances from csv file

Is there a way to drive the RGB material values of a single object that has multiple instances from a csv file where the index of the object instance and the index of the rgb values from the csv align?

Cheers


Yes there is a way.

Your problem is basically two (and quite standard) tasks:

  • read bunch of numbers from CVS. You can find tutorials about that.
  • second part is dynamically creating array of dynamic material instances, which is also standard task

However i ma not really certain:
do you want dynamic instanced materials, or bunch of instanced not dynamic materials?

So, all you want is to read those numbers and create instanced materials out of them.
Or you want to read those numbers and have them dynamically changing during runtime?

Because for reading bunch of CSV numbers then making batch task in editor that creates bunch on instanced materials. You need to watch tut about making blueprintable unreal editor tools.

For that tool all you need is event that you can trigger from actor that holds that mesh from picture. Event should create instanced materials in some folder, then apply them to meshes or components or material slots in mesh.

Get CSV into data table:

instanced materials:

And for tool that processes it all:

  • make actor that keeps that bars mesh as component.
  • make event that is "EVENT_process_csv

in that event: read that CVS into table

  • read CVS into table
  • go trough table and create instanced materials (you should work with material assets on disc not loaded copies in memory).
  • change their parameter, and save back. (to asset on disc!)
  • assign materials to slots

And i just asked my Yellow Rubber Duck about whole task (and checked if it is not total derpy derp ajj).

This is rubbers duck reply:

GOAL

Create and save multiple Material Instance Constants on disk:

  • Based on a master material.
  • Each with a different LinearColor parameter set (e.g., RGBA values).
  • Named and saved in a desired folder.

:brick: REQUIRED SETUP

1. Enable These Plugins:

  • :white_check_mark: Editor Scripting Utilities (Edit > Plugins > Editor)
  • :white_check_mark: Asset Tools Editor

Then restart the editor.

3. Variables Setup

Variable Name Type Details
MaterialTemplate MaterialInterface Expose On Spawn
OutputFolder String Default: /Game/Materials/Instances
ColorArray LinearColor Array Colors to assign
ParameterName Name Default: ColorTint or your param name

4. Function: GenerateMaterialInstances

Inside your EUB, add a custom function (or just logic in Run if you prefer) with the following:

:brain: Full Node Logic (in text form):

Loop over ColorArray (using For Each Loop)

Inside the loop:

  1. Create a New Material Instance Constant Asset
  • Use node: Create Asset
  • Asset Name: "MI_Color_" + Index
  • Package Path: OutputFolder
  • Factory: MaterialInstanceConstantFactoryNew
  • Set Factory’s Parent to MaterialTemplate
  1. Cast to MaterialInstanceConstant → Store as NewInstance
  2. Set Vector Parameter
  • Use: Set Vector Parameter Value
  • Target: NewInstance
  • Parameter: ParameterName
  • Value: Current LinearColor
  1. Save the Asset
  • Use: Save Asset (optional if you want to be safe)

Looks mostly correct, however that worst part about chatGPT, answers always look correct then it does totally bogus error in middle of all of it. But at least you have general idea described step by step.

1 Like

Legend, thanks so much mate