I just tried this all for myself in my own editor.
I didn't really need any of my recommendations. I was able to update the color and prevent errors both at design time and runtime using the following...
- Node2D (script)
- Sprite
Script:
tool
extends Node2D
export(Color) var color = Color(1,1,1,1) setget set_color
func set_color(p_color):
color = p_color
if has_node("Sprite"):
$Sprite.modulate = color
Now, when I updated it to use the onready
keyword and assumed that the node existed, I did get the desired functionality, but I would receive error messages only whenever I saved the scene (not whenever I just set the property in the editor). That might be a bug.
# Caused a bug on save
tool
extends Node2D
export(Color) onready var color = Color(1,1,1,1) setget set_color
func set_color(p_color):
color = p_color
$Sprite.modulate = color