0 votes

need delete SpatialMaterial from MeshInstance by code

Godot version 3.3.2.stable.official
in Engine by (159 points)

1 Answer

0 votes

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

by (4,084 points)

I tried it, but it doesn't work(

mesh_instance.material_override = null


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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.