Hi guys,
I am working on a game and I’m trying to read “Parameter Name” from materials that are assigned to the object.
So instead of hardcoding the parameter name, I’d like to read them from the material.
But my problem is that the node “Scalar Parameter Values” returns an empty array, even though there are scalar parameters on the material.
Is there any other way to read the parameter names?
There is, but its a bit roundabout and I believe it’s a bug that you cannot reference the name using your method. You should post a bug report on Answerhub about it.
The GetScalarParameterValues node can get parameter names from a constant material instance, not a dynamic one. So while it may be a pain in the ***, you need to use a material instance constant, rather than a base material, on any objects you want to create a dynamic material instance from, as in your post. Or, you need to create a variable map(I just noticed this in 4.15, you can now set this like you would set a variable as an array) between base material names, and a material instance constant derived from it.
If the dynamic material instance is derived from a constant one, you can first call get parent, which returns a material interface. Then cast that to a material instance, and use a GetScalarParameters node. Since the constant and dynamic material instances have the same names, you can use the array of names from the constant one to access the values of the dynamic one.
Sorry to necro the post, but I am having an issue, and I am trying to figure out if it’s a glitch of the new UE5 versions or if I am doing something wrong if you could help please.
Your solution works great for me when used with a vector parameter (thank you), but when I tried getting the list of scalar parameters from my material, the list returns empty for me!
I have searched up all over the forums and some other people seem to have encountered this issue too, but their issue had to do with booleans being set to false by default, whereas in my case, I have no booleans whatsoever, nothing fancy at all in the material set up really. It’s simply a color parameter called “MainColor” attached to the emissive channel and a scalar parameter named “Opacity” attached to the opacity channel.
Below is a picture of the code I am using to retrieve the list of material parameters. In a nutshell, the code is trying to retrieve all the scalar parameters that the material dynamic instance has. Then, it attempts to find a match between a string that this code receives and the array of parameters. If a match is found, then it sets the value, if not, then it sends out a warning to the user that the string they are setting does not exist as a parameter in the material.
I have also done some debugging, and the material instance states that the vector parameter is listed in the material’s parameters, but the scalar array is empty, despite the material having a scalar parameter value.
Anyone got any clue why this is? Thank you in advance!