Setting Material Slot Names on Static Mesh Materials not updating Editor UI

I’m trying to rename the material slots on the selected static meshes in the content browser. If I run the script below it works if I get the editor property and print it to log after settings it, but it doesn’t update the “Slot Name” field in the editor for the material on the selected static meshes.

The documentation says that using “set_editor_property” will force the editor UI update but it’s not in this case. Any idea’s what I’m doing wrong?

  selectedAssetsPaths = unreal.EditorUtilityLibrary().get_selected_assets()
  for asset in selectedAssetsPaths:
      materials = asset.get_editor_property("static_materials")
      for mat in materials:      
          mat.set_editor_property("material_slot_name", "New Slot Name!")

This was resolved in a post off this forum. Putting the answer here for anyone else that needs it.

"It seems that for whatever reason, it keeps overwriting the changes immediately after they are made (like it is force reloading the asset from the editor). I was able to find a way around this by making a copy of the materials and changing that copy, before reassigning it back into the asset.

This seems to work for me. Note: for some reason I had to also reassign the mateial back into the array or again it would overwrite itself"

selectedAssetsPaths = unreal.EditorUtilityLibrary().get_selected_assets()
for asset in selectedAssetsPaths:
	mats = asset.static_materials.copy()
	for i, mat in enumerate(mats):
		mat.material_slot_name = "New Slot Name!"
		mats[i] = mat
	asset.static_materials = mats
1 Like

Thank you so much! Took me 2 hours of sanity checks to figure this out :sweat_smile:

Btw if you want to change the material in the renamed slot, you have to assign it in the same loop with mat.set_editor_property('material_interface', newMaterial)