This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I am trying to make a mesh that starts off as a colour and fades to black as damage is applied.

Is their any capability to do this?

in Engine by (52 points)

1 Answer

0 votes

You should be able to do that by modifying its material's diffuse color. If your mesh is not too complicated, you can create a new material override (in MeshInstance) and modify the diffuse color of this one only, so it won't affect other instances of the same mesh.

by (29,510 points)

This is what I have so far

var mesh = meshNode.get_mesh(); 
var mat = mesh.surface_get_material(0);     
mat.diffuse = 0;    
mesh.surface_set_material(0, mat);

But mat is returning null.

This is what I have for the editor.

enter image description here

You can apply a material override in the inspector, or using the following code:

# Create a new FixedMaterial (for example)
var new_material =

# Assign it on the mesh as an override

# Modify the material (it will be applied on all meshes you use it on, here only one)
# Note: if you need a texture or other setup, you may want to set more params
new_material.set_parameter(Material.PARAM_DIFFUSE, Color(0,1,0))
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.