–1 vote

the docs dont explain it very well

asked Aug 17 in Engine by Newby (194 points)

1 Answer

0 votes

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.

answered Aug 17 by Zylann (14,838 points)
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 How to use this Q&A? before posting your first questions.