I’ve been looking for a solution for a while now. I searched on the internet and tried out some stuff, but couldn’t find a way to do this. Is there a way to access Megascans material parameters via blueprints?
You need to create your own material base that has the exposed parameters you want to edit, and set that material up as the master material to use when importing the megascans. There’s a naming convention to make the Bridge generate the appropriate material instances for you.
Then you do as usual: get the materials from the mesh and create the MID (material instance dynamic) on it on startup, and push values into the parameters when you need to.
Thanks for the answer! Do you know where to get such a custom master material? I could probably create one with a lot of effort, but for sure someone else on the internet has done this before
You could clone the master material the Bridge creates, and turn the textures it generates into parameters.
It’s generally just a straightforward “use the 2/3/4 maps, separate out the channels, and plug them into the Material output,” nothing fancy.
Come to think of it, doesn’t it do this already? Maybe all you’re missing is the CreateMaterialInstanceDynamic setup in the construction script, to turn the mesh material into an instance you can change at runtime?
Yeah, the default master material already does this:
This is an instance from a downloaded/placed material instance.
So all you need to do is to create the MID (Material Instance Dynamic) on the static mesh component and update the parameters like normal.
Btw, your original blueprint had a few points to change:
- The material didn’t have a parent to be created from
- You didn’t assign the material to anything
- You created it in the event, rather than on startup – you only need to replace the material on a mesh once, making new materials is inefficient
Thank you! I think I should have explained my project a little more in the first place…
Putting this blueprint inside a Static Mesh Actor doesn’t work for what I want to do.
Basically I dynamically load textures from a folder in a list. I would like to be able to click on a material in that list and change for example the scale or the color tint.
I already achieved to activate the material you click on. The only problem is, that from there on, I can’t change the parameters of the according material.
Do you have an idea how to edit the parameters that way?
It’s still all “Create Material Instance Dynamic” after loading/creating the material, and calling Set Texture Parameter Value on it.
There is some geometry you render. That geometry must have a dynamic material, created based on its “normal” static material. And once it does, you can update the parameters whatever way you want. Doesn’t matter much if it’s a procedural mesh, a static mesh, a skinned mesh, or some other geometry.
You do need a parameter for each thing you want to be able to change. So, clone (or edit) the base material that Bridge makes for you, to add whatever the parameters are that you want to be able to change.
So it is not possible to just edit the materials from that list itself, without it being assigned to a mesh?
If I understand it right, if you create a dynamic material instance it is just temporary and not permanent to that inital material…?
There’s no way to edit the material itself?
At runtime, there is no way to edit the material itself, no.
However, you generally don’t want to do that – materials are compiled shaders, that require the build pipeline to build correctly for all the possible permutations.
Instead, you can save a map of material parameter names and values. Create a struct or object of some sort, that contains the things you want to override. Then write a function that takes one of these configurations, and applies it to the underlying material. When you “save” the edits, you save this struct (containing the configuration information,) not the material itself. When you “load” the edits, you load the struct, and re-apply the saved data to the material instance.
Thank you for your help!