How to modulate in script

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

the docs dont explain it very well

:bust_in_silhouette: Reply From: Zylann

In Godot 3, modulate is a property. You can set it from a script by writing modulate = Color(0,1,0). There is no example of how to set it because we would have to write one for every single property of every class, so instead you should learn how properties work. They are just like variables that have internal getter and setters (so you can use set_modulate(Color(0,1,0)) too) but it’s just easier to use the property shortcut.

Example 1:

extends Sprite

func _ready():
    modulate = Color(0,1,0)

Example 2:

extends Node

func _ready():
    # If MySprite is a child
    get_node("MySprite").modulate = Color(0,1,0)

Note: in Godot 2 properties did not exist so you could ony use set_modulate or get_modulate.

For me this did not work. To anyone with the same problem use Color8() and not Color()