I made a model and input it into the engine, then set all the Surface Material Override slots. But when I re-input the model, all of the Surface Material Override slots clear automatically. I have to set all the material again whenever I adjust the model. How to keep it didn’t change automatically?
the materials override are part of the MeshInstance3D node not the MeshResource. If you want to keep the materials between MeshInstance3D nodes you’ll need to set them in the MeshResource itself.
If the Mesh is part of an imported scene (glb, gltf, dae,… file) then you have two options:
@tool
extends EditorScenePostImport
func _post_import(scene):
iterate(scene)
return scene
func iterate(node):
if node != null:
if node is MeshInstance3D:
# Override the materials of the mesh with a custom material
var mesh:Mesh = node.mesh
for i in mesh.get_surface_count():
mesh.surface_set_material(i, preload("res://assets/kaykit dungeon/dungeon_material.tres"))
# Keep iterating
for child in node.get_children():
iterate(child)