Get the name of current material used from a meshinstance3d via code

Get the name of current material used by a meshinstance3d via code.
For example material used by is “mat1.tres” under “res://materials/mat1.tres”

You can get the path with Resource.resource_path and the name with Resource.resource_name

You can get the active material for an specific surface with MeshInstance3D.get_active_material()

var mat2save = get_surface_override_material(0)
var err := ResourceSaver.save(mat2save, res://materials/textures/mat1.tres)
print(mat2save:,mat2save.resource_name)
print(resourcepath:,mat2save.resource_path)

output:
mat2save:
resourcepath:res://node_3d.tscn::StandardMaterial3D_4lw32

I dont get any path or name
i mean: res://materials/textures/mat.tres
or mat1.tres

That means that the Resource is not saved to disk but it’s saved as a sub-resource inside the tscn file.

Try loading back the Resource after you save it.