# Python Material Instance 'Save'

**URL:** <https://forums.unrealengine.com/t/python-material-instance-save/2081444>\
**Category:** Editor Scripting\
**Tags:** unreal-engine, editor, question\
**Created:** [October 23, 2024, 12:25am UTC](https://forums.unrealengine.com/t/python-material-instance-save/2081444 "2024-10-23T00:25:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MelonySharon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MelonySharon](https://forums.unrealengine.com/u/MelonySharon)\
**Post date:** [October 23, 2024, 12:25am UTC](https://forums.unrealengine.com/t/python-material-instance-save/2081444/1 "2024-10-23T00:25:29Z")

</div>

( obviously: there is ‘more’ to this script than quoted below, it’s just for reference )

When I run my script;

1. Material Instances are created
2. Material Instances have textures are applied
3. Material Instances are applied to meshes – all is fine –
4. Exit unreal engine
5. Reload the project ALL settings made to the material instance(s) are lost

What am I missing after making change to the material instance, the editor doesn’t tell me that anything needs to be saved, I’m guessing it’s one line of code I need to add to Build\_MaterailInstanceTextures() ?

> def Set\_MaterialInstance(material\_instance,texture,texture\_slot\_name,uv\_slot\_name,uv\_channel):  
> unreal.MaterialEditingLibrary.set\_material\_instance\_texture\_parameter\_value(material\_instance,  
> texture\_slot\_name,  
> texture)
> 
> ```
> unreal.MaterialEditingLibrary.set_material_instance_scalar_parameter_value(material_instance,
> uv_slot_name,
> uv_channel)
> 
> ```

> - 
> - Build Material Instance Textures, eg. insert textures into the materials and other additional setup.
> - 
> 
> def Build\_MaterailInstanceTextures(j,sub\_model\_idx):  
> mm\_inst\_id = f’MM\_I\_{jCreate\_MaterailInstID(j,sub\_model\_idx)}’  
> mm\_inst\_path = f’/Game/Material/Pool/{mm\_inst\_id}/{mm\_inst\_id}’  
> pram\_texture\_name = [‘Base’,‘LayerA’,‘LayerB’,‘LayerC’]  
> pram\_uv\_name = [‘UV Index Base’,‘UV Index Layer A’,‘UV Index Layer B’,‘UV Index Layer C’]
> 
> ```
> for idx, i in enumerate(j['submodels'][sub_model_idx]['texture_indices']):        
> texture_file_id = int(j['textures'][i]['file_hash'])
> texture_file_path = Locate_Texture(texture_file_id)
> texture_uv_channel = j['submodels'][sub_model_idx]['texture_uv_map_index']
>     
> print(f' !!! {mm_inst_path} @ {texture_file_path}')
> if idx==0: # Base Texture
> Set_MaterialInstance(EALib.load_asset(mm_inst_path),
> EALib.load_asset(texture_file_path),
> pram_texture_name[0],
> pram_uv_name[0],
> texture_uv_channel[0])
> else:
> Set_MaterialInstance(EALib.load_asset(mm_inst_path),
> EALib.load_asset(texture_file_path),
> pram_texture_name[idx],
> pram_uv_name[idx],
> texture_uv_channel[idx])
> 
> ```

neither;  
EALib.save\_asset(mm\_inst\_path)  
or  
unreal.EditorAssetLibrary.save\_loaded\_asset(my\_new\_asset)

have any effect on saving the changes to the material instances at all, exit editor, all changes gone.

Yet, if I physically open the material instances and click the ‘save’ button, it will keep the changes over exit editor / reload.

---

<div class="post-metadata">

**Author:** ![MelonySharon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MelonySharon](https://forums.unrealengine.com/u/MelonySharon)\
**Post date:** [October 23, 2024, 1:26am UTC](https://forums.unrealengine.com/t/python-material-instance-save/2081444/2 "2024-10-23T01:26:40Z")

</div>

Nevermind;

unreal.EditorAssetLibrary.save\_loaded\_asset(mm\_i\_id,False)

Setting to ‘FALSE’ fixed it.

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [November 22, 2024, 1:27am UTC](https://forums.unrealengine.com/t/python-material-instance-save/2081444/3 "2024-11-22T01:27:38Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
