How to change color in code?

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

Link:

:bust_in_silhouette: Reply From: DDoop

Does the answer to this question help?

:bust_in_silhouette: Reply From: Gluon

If you use something like the below it should do the job

var new_material = SpatialMaterial.new()
new_material.albedo_color = Color(number, number, number)
self.material_override = new_material

replace the numbers in the color() function with actual numbers (red, green, blue) to make the colour you want.

There are even constants that do this for you like

new_material.albedo_color = Color.red
new_material.albedo_color = Color.purple
new_material.albedo_color = Color.aqua

Wakatta | 2022-11-14 22:52

If you check the image, OP is asking specifically about shader params I believe, but they didn’t explicitly ask.

DDoop | 2022-11-14 23:15

Still applies

Wakatta | 2022-11-15 00:38

I need to change color in shader parameters but this code changes Mesh color

johnny_glad | 2022-11-15 09:19

Alright try,

new_material.set_shader_param("albedo", color.red)

in place of the second line and see if that does what you want.

Gluon | 2022-11-15 09:54

:bust_in_silhouette: Reply From: Wakatta
var material = $MeshInstance_HODD_Left.get_surface_material(0)
material.set_shader_param("Color", Color.red)
material.set_shader_param("Light_Color", Color.blue)
$MeshInstance_HODD_Left.set_surface_material(0, material)

All OK. Thanks.

johnny_glad | 2022-11-15 09:10