how to delete SpatialMaterial from MeshInstance?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Timofey

need delete SpatialMaterial from MeshInstance by code

:bust_in_silhouette: Reply From: klaas

Hi.
Its actually not a delete but you can set material properties to null

#get surface count
var surf_count = $MeshInstance.mesh.get_surface_count()
for i in range(surf_count):
	#for each of the surfaces, set material to null
	$MeshInstance.mesh.surface_set_material(i, null)
#also set the override material to null
$MeshInstance.material_override = null

this will leave the mesh unrenderable … it will not be shaded after that

I tried it, but it doesn’t work(

mesh_instance.material_override = null
print(mesh_instance.get_surface_material(0))

[SpatialMaterial:1215]

Timofey | 2021-08-16 18:02

what do you mean … it doesnt work? Can you be more specific?

Whats your code about? you set the override material to null and then read a surface material? This does not make much sense.

What do you try to archive with setting the materials to null?

And i have to correct myself … after setting everything to null the instance gets shaded with the default shader.

klaas | 2021-08-16 18:07

I set null like you did, then check for availability. The material is still there. I need to remove the material completely. i made 3D model from svg file (figure with a solid color) + scale + extrude, if I set the material, the color of the model is automatically replaced by the color of the material.

Timofey | 2021-08-16 18:36