I'm trying to create a custom control that has child controls. I want it to behave like any other control in the editor with persistent properties.
Example:
A custom control "scene" with class named "Indicator" that extends ColorRect. Indicator has a Label child node named "IndLabel". I want to be able to create multiple Indicator instances in a "Main" scene and set IndLabel.Text property for each instance.
The first problem was Indicator.ind_label is null when Indicator.label_set is called by the editor. I solved this by wiring up the "ready" event from ind_label to Indicator.on_IndLabel_ready().
The next problem is when I set the "Indicator Label" value on an instance in Main, the value is lost when I change to editing another scene. What am I missing? How do I persist the values in the Main scene? All suggestions are welcome.
Indicator script:
tool
extends ColorRect
class_name Indicator
onready var ind_label:Label = get_node("IndLabel");
export (String) onready var IndicatorLabel:String setget _label_set, _label_get
func _ready():
pass # Replace with function body.
func _label_set(label_text:String)->void:
if ind_label != null:
ind_label.set_text(label_text);
func _label_get()->String:
if ind_label == null:
return "";
else:
return ind_label.get_text();
func _on_IndLabel_ready():
_label_set(IndicatorLabel);
IndLabel script:
tool
extends Label
class_name IndLabel
func _ready():
pass # Replace with function body.