problem with consruction script and material parameters

I have mesh with two material IDs that each have same Instance of the Master Materials containing several scalar parameters.

In the construction script i have ‘Set Scalar Parameters Value’ that can change Emmisive intenisity per Mesh ID.
Problem is if I set ID_0’s Emmisive = 5 and then switch to ID_1 then Emmisive parameter of ID_1 automatically sets itself to 5.

here is how my Constr. Script looks like. Please help, i have no idea how to prevent copying values from one ID to another one.

I believe you need to create an instance of the material for each ID and set the scalar value for each. You can do a for loop and get the number of materials the mesh has, loop N-1, and do pretty much what you have now except for changing the value of the emmisive and using the array index for the element index.

Well, problem is something else i think. In the setup in my first post, i use two variables, ‘ID’ and ‘EmmisiveINT’. If i set ‘ID’ = 0 and change value of emmisive strength to 5, it works fine and changes emmisve strength only in Id 0’s material.
However, if i switch to ID 1, then construction scripts kicks in, reads value from ‘EmmisiveINT’ variable and assigns it to emmisive strength in ID 1, and completely ruins my previous settings.
In short, upon switching from one Id to another, all values are copied over.
How do i prevent that?

Thanks for the input anyway.

You will need to save the material instance to a variable after it is created, and will need to do that for both ID’s.

For example:

Once the DMI is created, save the output to a variable called mid1 (or anything, doesn’t matter). Next immediately call another Create Dynamic Material Instance using the other ID and again save the output to a new variable named mid2.

Now when you call Set Scalar Parameter (either in the construction script, or elsewhere) you can use the mid1 or mid2 variable as the “Target”. The way you have it set now it is overwriting itself every time you switch ID #, you need to save the created instance to prevent this.

Hope that helps!

oh man! it DOES help, a lot actually! thanks!

All the advice helps a lot (thanks DotCam!) but one fundamental problem is, if i use one variable (in this case is EmmisiveINT) in the construction script for multiple ID# it will read value from that variable and apply it to the next ID# when i switch to next ID#.
I made check to detect if the id selection changes and then it reads the existing emmisive values from newly selected ID# and applies it to the variable in the construstion script so there is no overwriting.

And that’s somehow problem.
This setup, sometimes works sometimes doesnt, i have no idea why. Sometimes the array has correct length (around 4 scalar variables) sometimes it has 0. Any advice how to get it work reliably?