( obviously: there is ‘more’ to this script than quoted below, it’s just for reference )
When I run my script;
- Material Instances are created
- Material Instances have textures are applied
- Material Instances are applied to meshes – all is fine –
- Exit unreal engine
- 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.