Change parameters of mesh with multiple materials

Greetings, i’m currently working on a Top/Down Adventure game and i’ve stumbled upon a problem I’m not exactly sure how to fix.
So basically I have a blueprint that makes a mesh turn transparent if it gets into collision with the player camera. This system works fine but the problem is that it only works if the mesh has one material. I kinda understand where the problem is I just don’t really know how to implement a solution.
I believe that the solution lies with how the dynamic material is created in Event BeginPlay. When I GetMaterial from the Static Mesh the element Index is set to 0 so I imagine thats why it only affects the first material and not the rest. Im not sure how I would go about making it create a dynamic material for each material within the static mesh. Arrays are probably the solution? Any ideas?


if you have multiple materials then you should just need a loop which repeats the process for each material. on begin play you will get the number of materials then run a for loop for each material. the get num materials node should output a number greater than zero and the material indexes are zero based so you will likely need to subtract one from the num materials. after that is basically the same procedure you were doing. the exception comes at the end where your storing the materials in a variable, here you will want to add them to an array via the add node. the other change comes in your update vis function here you will again need to loop to go through each material instance. so you get your array and use a for each loop which will run the script following it for every material stored in the array.

I’ve added what you suggested but i’m having the same result i’m not sure why. It still only makes the first material disappear.

Ok Ive figured it out, basically it does actually work but not with the system ive got. If I connect the Completed node from the ForEachLoop to the Return Node it does affect all the materials but it wont go back to its initial opacity once the mesh is not in contact with the player camera. Ill just modify my system a bit so it works properly.
Thanks a lot for the help.