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


: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 =
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 =
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,


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)
$MeshInstance_HODD_Left.set_surface_material(0, material)

All OK. Thanks.

johnny_glad | 2022-11-15 09:10