Custom controls with child controls and how to persist exported properties

tx350ztx350z Posts: 11Member

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.

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:

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:

func _label_get()->String:
    if ind_label == null:
        return "";
        return ind_label.get_text();

func _on_IndLabel_ready():

IndLabel script:

extends Label

class_name IndLabel

func _ready():
    pass # Replace with function body.

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file