Godot 4: Replace texture with one color

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

I had this code working in Godot 3.5:

mesh_material = mesh.get_surface_material(0)
color = mesh_material.get_albedo()
color.a = 0.5
controller_hand_mesh_material.set_albedo(color)

Mesh has a texture on Surface 0 and it was simply replaced by color (in this case white with 50% opacity).

In Godot 4 it doesn’t change anything. I tried different functions, but never found working solution.

I was thinking about simply removing texture, so the only information is from albedo color, but I don’t know how to remove a texture.

:bust_in_silhouette: Reply From: Wakatta

The material you get is not the same as the mesh’s so you also need to set

mesh.set_surface_material(0, mesh_material)

You have two above so ensure you’re using the correct one

To remove a texture

mesh_material.set_texture(null)