Get Scalar Parameter Values doesn't work! Why?

Get Scalar Parameter Values doesn’t work! Why? Here I trying to get number of scalar parameters in Instanced Material.

That node is a bit silly, it doesn’t work with dynamic material instances, only constant. What you can do is get the parent of the material instance you’re creating, cast it as a MaterialInstance (not dynamic), then get the scalar parameters of that one. If you need the values too you can use a for loop with the scalar parameter array as the input, break the array element and hook the Name into a GetScalarParameterValue (from your dynamic material instance) in the loop.

1 Like

you can use a scale to parameter value in materials. This is great documentation from epic team.
It’s a difficult project to run but kite demo has a lot of advanced material creation in the landscape.
I learned a lot.

Cyaoeu, doesn’t work ether. Thou maybe I doing something wrong… Here’s my setup I trying now. It just fires off “Casting Failed” rout. I did tried CastToMaterialInstanceConstant as well with the same result.

Get Scalar Parameter Values only works after you manually call get x parameter or set x parameter nodes for each parameter. Probably a bug.

1 Like

Well you need to have an actual constant material instance first, create that by right clicking your material and creating a material instance in the content browser. Then create your dynamic version from that.

Thanks, it works. Already done this. Must notice that parameters in instance must be activated for editing. Otherwise they still will be inaccessible in BP.
That’s still looks and feels like a bug. And cause a lot of confusion. Hope this will be fixed someday… As well as everything else… ~~’

1 Like

How did you get it to work? I have the same issue in 4.19.2 . See Imgur: The magic of the Internet for reference.

The GetScalarParameterValues array returns 2 elements only when I cast to Material Instance Constant and then get it but returns 0 elements when using Material Instance Dynamic.

It works only if you create Dynamic material instance from static material instance. Also in static material instance You should have enabled fields you want for edit. It will not work if you create dynamic material instance directly from material.

Hi there!

I would like to expose material parameters to the UI so the player can edit material instances at runtime(i.e. color, roughness of objects, etc).

I have a base class, that is the parent of everything in game; that has a variable of type Material Instance Dynamic called WMaterialInstance. It also has an Interface function to return that var.

Please see the construction script.

I’d like read parameters of this instance and expose it to the UI somehow.

But I can’t get those parameters…

I am using a Get Scalar Values node to get my params…

I tried feeding it a Material Instance Dynamic reference, but my Print String nodes return zero, although there are parameters on the material, 100%.

Please see the BP nodes here.

I had a look at this post:

So I got the parent of my Material Instance Dynamic and tried casting it to just a normal MaterialInstance, but the cast seems to fail, if I feed the parent to it…

Here is how I did it.

Note: the Get Material node is my interface call to the Dynamic Instance from construction script, not the built in one.

Further down in the post:

I created a material instance from my original material and assigned it to one of the child classes of the baseclass, so I use that one in the base construction script.
Still, doesn’t want to work… I get the same zeros and cast failures…

I noticed, that if I Print String the Display name of the Parent I get from the accessed base material it prints WorldGridMaterial, which means, it did not find what it supposed to…

Is there a better way to access these parameters?

It may be worth noting that if you have a dynamic material you do not need to read any values.
You can simply set the value to whatever you want, and use the value/variable used for setting it as if you were actually using a “get” of some sort.

There is a difference between Material Instance and Material Instance Dynamic - you need the latter which can be modified during run-time. Instead of setting a scalar, you can, of course get it, too. Other than that, I’m not sure if I follow the setup.

If the goal is to have multiple objects whose materials are individually modifiable by a single UI widget, have each object create their own MID and store it in a variable, as above.

Once the object is chosen / selected, you send the reference of its MID to the widget. Or bind the widget’s functionality to the selected object’s events. This way you can have a single widget element control multiple parameters - optional, of course.

谢谢,太有用了