instance is already set to the reference.
if i did scalar_value= instance.get_scalar_parameter_value(“TestVal”)
print scalar_value i would get 1.0
i want to be able to set the value of that scalar parameter
i have tried
instance.set_editor_property(“scalar_parameter_values”,(parameter_info=‘TestVal’, MaterialParameterAssociation.GLOBAL_PARAMETER, -1], parameter_value=0.0))
I have tried various version of this line of code but get the error: LogPython: Error: SyntaxError: invalid syntax (<string>, line 1)
I played around with this and got the following to work, not sure if this will work for you. I tried to use the set_editor_property and could not get anything to work either.
paramInfo = instance.scalar_parameter_values
print paramInfo
#LogPython: {parameter_info: {name: "testVal", association: GlobalParameter, index: -1}, parameter_value: 1.000000}, {parameter_info: {name: "RefractionDepthBias", association: GlobalParameter, index: -1}, parameter_value: 0.000000}]
#because i got an array, i need to check and make sure i am adjusting the right one.
for i in range(len(paramInfo)):
if paramInfo*.parameter_info.name == "testVal":
print "Found Parameter"
newParams = paramInfo* #i made a copy
newParams.parameter_value = 1.2 # adjusted the value
paramInfo* = newParams #copied all the values back to the array
print instance.get_scalar_parameter_value("testVal")
#LogPython: 1.20000004768
After running the above code i reloaded the material instance in the material editor and the values changed. Note: For some reason if the material instance was already loaded and you run the code, the changes do happen behind the scenes, but don’t show up in the editor until you reload it. Meaning you need to close and double click on the material instance again to see the changes
I’m completly stuck in this part right now, I gonna try to understand how to do it in C++ and then replicate it in Pyhton, maybe someone can bring us some light into this… I’m lost xD
I have checked it and we don’t have this method in python, I can assume that we shoud replicate it with “set_editor_property” but does not work for me in any case.
Ok! I found a way to do it, I modfied the previus code to show you.
At the same way that you can set a parameter into a dict, you can make a copy and set the name of the parameter, if it exists,automatically the checkbox is turned on.
for i in range(len(paramInfo)):
if paramInfo*.parameter_info.name == "testVal":
print "Found Parameter"
newParams = paramInfo* #i made a copy
newParams.parameter_value = 1 # adjusted the value
paramInfo* = newParams #copied all the values back to the array
else:
new_param = paramInfo*
new_param.parameter_info.name = "testVale"
new_param.parameter_value = 1
paramInfo* = new_param
#select your mats in Content Browser you want to enable all paramters on
import unreal as ue
# create unreal class instances
edutil = ue.EditorUtilityLibrary()
mated=ue.MaterialEditingLibrary()
# get the selected assets
selected_assets = edutil.get_selected_assets()
for inst in selected_assets:
for sc_name in mated.get_scalar_parameter_names(inst):
value=mated.get_material_instance_scalar_parameter_value(inst,sc_name)
mated.set_material_instance_scalar_parameter_value(inst,sc_name,value)
for c_name in mated.get_vector_parameter_names(inst):
value=mated.get_material_instance_vector_parameter_value(inst,c_name)
mated.set_material_instance_vector_parameter_value(inst,c_name,value)
for t_name in mated.get_texture_parameter_names(inst):
value=mated.get_material_instance_texture_parameter_value(inst,t_name)
mated.set_material_instance_texture_parameter_value(inst,t_name,value)
Thank you so much! Your code on github is working for me.
I needed to change the texture if clause to “if type(param_value) == unreal.Texture or type(param_value) == unreal.Texture2D:”
Updating values in a MaterialInstance is not working like with an actor using set_editor_property…