Change a SpatialMaterial to change one MeshInstance color ?

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

I am actually working on a simple project and I want some cube to disappear slowly when the arrived in a CollisionShape. So I decided to use a Tween to interpolate the alpha property of the albedo of the material of the meshInstance. But this change work for every cube of the world and I don’t understand why. Here is my code :

func disappear(): var mat = $MeshInstance.get_mesh().get_material().duplicate() var tween = Tween.new() add_child(tween) tween.interpolate_property(mat, "albedo_color:a", 1, 0, 1, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) tween.start() $MeshInstance.get_mesh().set_material(mat)

The function disappear() is call when the object collide with the collisionShape.
My cube object is very simple. This is a StaticBody composed of a MeshInstance and a CollisionShape
Thanks for any help !