# Setting Properties on Material Instances

**URL:** <https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943>\
**Category:** Editor Scripting\
**Tags:** unreal-engine\
**Created:** [June 24, 2019, 3:15pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943 "2019-06-24T15:15:46Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![westcut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@westcut](https://forums.unrealengine.com/u/westcut)\
**Post date:** [June 24, 2019, 3:15pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/1 "2019-06-24T15:15:46Z")

</div>

Hello,  
I am trying to set some parameters on my material instance to automate the process and i made a simple instance to test it on.

 ![Untitled.png](https://d3kjluh73b9h9o.cloudfront.net/original/3X/3/3/33f36e3b7aed7d62eaae04bec8fec149801588bd.png)  
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)

---

<div class="post-metadata">

**Author:** ![cgsquirrel2](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@cgsquirrel2](https://forums.unrealengine.com/u/cgsquirrel2)\
**Post date:** [June 24, 2019, 8:50pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/2 "2019-06-24T20:50:00Z")

</div>

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.

```auto

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

---

<div class="post-metadata">

**Author:** ![duke22](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@duke22](https://forums.unrealengine.com/u/duke22)\
**Post date:** [June 25, 2019, 10:31am UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/3 "2019-06-25T10:31:54Z")

</div>

Or grab my EditorPlus plugin, switch to the 4.22 branch and use this:

​https://github.com/GeorgeR/EditorPlus/blob/4.22/Source/EditorPlus/Classes/Scripting/EditorMaterialLibrary.h​​​​​​

---

<div class="post-metadata">

**Author:** ![westcut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@westcut](https://forums.unrealengine.com/u/westcut)\
**Post date:** [June 25, 2019, 3:31pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/4 "2019-06-25T15:31:40Z")

</div>

> [@duke22](#):
>
> Or grab my EditorPlus plugin, switch to the 4.22 branch and use this:
> 
> ​[https://github.com/GeorgeR/EditorPlus/blob/4.22/Source/EditorPlus/Classes/Scripting/EditorMaterialLibrary.h​​​​​​](https://github.com/GeorgeR/EditorPlus/blob/4.22/Source/EditorPlus/Classes/Scripting/EditorMaterialLibrary.h%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B%E2%80%8B)

Tried to use it but it refused to build. will try again later also the link you gave is broken

---

<div class="post-metadata">

**Author:** ![KaitoDBM](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaitodbm/32/742389_2.png) [@KaitoDBM](https://forums.unrealengine.com/u/KaitoDBM)\
**Post date:** [July 4, 2019, 6:26pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/6 "2019-07-04T18:26:12Z")

</div>

Hi !

How do you turn on the checkbox parameter in python?

---

<div class="post-metadata">

**Author:** ![westcut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@westcut](https://forums.unrealengine.com/u/westcut)\
**Post date:** [July 8, 2019, 3:10pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/7 "2019-07-08T15:10:00Z")

</div>

> [@KaitoDBM](#):
>
> Hi !
> 
> How do you turn on the checkbox parameter in python?

unfortunately havent figured that part out as we move on from that section it is on hold for now

---

<div class="post-metadata">

**Author:** ![KaitoDBM](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaitodbm/32/742389_2.png) [@KaitoDBM](https://forums.unrealengine.com/u/KaitoDBM)\
**Post date:** [July 8, 2019, 5:11pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/8 "2019-07-08T17:11:59Z")

</div>

Thanks for the reply ,

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

---

<div class="post-metadata">

**Author:** ![westcut](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@westcut](https://forums.unrealengine.com/u/westcut)\
**Post date:** [July 8, 2019, 5:21pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/9 "2019-07-08T17:21:22Z")

</div>

Ye i made a UDIM texturing system that handles that but setting the bool was annoying

---

<div class="post-metadata">

**Author:** ![KaitoDBM](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaitodbm/32/742389_2.png) [@KaitoDBM](https://forums.unrealengine.com/u/KaitoDBM)\
**Post date:** [July 8, 2019, 6:50pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/10 "2019-07-08T18:50:44Z")

</div>

A friend just told me how he do this in C++:

SetTextureParameterValueEditorOnly(FMaterialParameterInfo(“Diffuse”), GetTextureByName(Textures[animaMat-\>mDiffuseIndex].mName, ConnectionSlot::DiffuseSlot));

> **[UMaterialInstanceConstant](https://docs.unrealengine.com/4.27/en-US/API/Runtime/Engine/Materials/UMaterialInstanceConstant/)**
>
> Material Instances may be used to change the appearance of a material without incurring an expensive recompilation of the material.

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. ☹

Grettings,

---

<div class="post-metadata">

**Author:** ![KaitoDBM](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaitodbm/32/742389_2.png) [@KaitoDBM](https://forums.unrealengine.com/u/KaitoDBM)\
**Post date:** [July 8, 2019, 10:02pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/11 "2019-07-08T22:02:03Z")

</div>

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.

```auto

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

```

---

<div class="post-metadata">

**Author:** ![KaitoDBM](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/kaitodbm/32/742389_2.png) [@KaitoDBM](https://forums.unrealengine.com/u/KaitoDBM)\
**Post date:** [July 9, 2019, 10:06pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/12 "2019-07-09T22:06:57Z")

</div>

I made a couple of functions in order to create or modify material instance parameters:

> <https://gist.github.com/animationdavid/c76129710f628d473fae9708b66fcfd1>

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_84db790b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_84db790b](https://forums.unrealengine.com/u/anonymous_user_84db790b)\
**Post date:** [July 18, 2019, 1:52pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/13 "2019-07-18T13:52:57Z")

</div>

> [@](#):
>
> [192.168.1.1](https://192168-1-1.info/) [192.168.0.1](https://192168-0-1.com/) [10.0.0.1](https://10-0-0-1.com)
> 
> Tried to use it but it refused to build. will try again later also the link you gave is broken

SetTextureParameterValueEditorOnly(FMaterialParameterInfo(“Diffuse”), GetTextureByName(Textures[animaMat-\>mDiffuseIndex].mName, ConnectionSlot::DiffuseSlot));

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_f92919d11](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_f92919d11](https://forums.unrealengine.com/u/anonymous_user_f92919d11)\
**Post date:** [June 11, 2021, 4:26pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/16 "2021-06-11T16:26:25Z")

</div>

I did it this way, using your idea 🙂

```auto
#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)

```

---

<div class="post-metadata">

**Author:** ![JanHxH\_de](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@JanHxH\_de](https://forums.unrealengine.com/u/JanHxH_de)\
**Post date:** [August 9, 2023, 3:48pm UTC](https://forums.unrealengine.com/t/setting-properties-on-material-instances/127943/17 "2023-08-09T15:48:14Z")

</div>

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…
