Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unreal Material Utils
def getMaterialInstanceParameters(material_instance, parameters):
param_names = []
for param_info in parameters:
str_name = str(param_info.parameter_info.name)
if str_name:
param_names.append(str_name)
return param_names
def setMaterialInstanceParameter(material_instance, param_name, param_value):
param_info = unreal.MaterialParameterInfo(name=unreal.Name(param_name), association=unreal.MaterialParameterAssociation.GLOBAL_PARAMETER, index=-1)
if type(param_value) == float:
parameters = material_instance.scalar_parameter_values
parameter = unreal.ScalarParameterValue(parameter_info=param_info, parameter_value=param_value)
if type(param_value) == unreal.LinearColor:
parameters = material_instance.vector_parameter_values
parameter = unreal.VectorParameterValue(parameter_info=param_info, parameter_value=param_value)
if type(param_value) == unreal.Texture:
parameters = material_instance.texture_parameter_values
parameter = unreal.TextureParameterValue(parameter_info=param_info, parameter_value=param_value)
parameter_names = getMaterialInstanceParameters(material_instance, parameters)
if param_name not in parameter_names:
#todo: check if the parameter exists in the parent material: parent_material = material_instance.parent.get_base_material()
parameters.append(parameter)
else:
for i in range(len(parameters)):
if parameters[i].parameter_info.name == param_name:
new_params = parameters[i].copy() #struct copy
new_params.parameter_value = param_value
parameters[i] = new_params
return parameters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.