I cannot save change to existing tres material loaded in a MeshInstance3d

Godot Version


<! #How can i save the current material change in the current material loaded on on the disk? The following code is contained in a script in a MeshInstance3D.
# The material is a standard material
#Let’s say resource name is mat1.tres, thanks a lot.

func create_material():

var tx_alb = preload("res://txtrgen/megafactory/albedo.png")
var tx_dis = preload("res://txtrgen/megafactory/displacement.png")
var tx_nor = preload("res://txtrgen/megafactory/normal.png")
var tx_rgs = preload("res://txtrgen/megafactory/roughness.png")

get_surface_override_material(0).set("albedo_texture", tx_alb)
get_surface_override_material(0).set("heightmap_texture", tx_dis)
get_surface_override_material(0).set("normal_texture", tx_nor)
get_surface_override_material(0).set("roughness_texture", tx_rgs)

var err := ResourceSaver.save(material, "user://mat1.tres")
if err:
    push_warning("Failed to save new material")

I’ve fixed.
I had to declare material as var material = get_surface_override_material(0) otherwise your code isn’t working. Neither returns an error.
Or better says you’ve to declare a resources…
Thanks however.