• Godot HelpGUI
  • Why are child node references null when a component is nested?

I'm trying to create a control that contains another control that I've created. I'm running into the problem that when I do this the child component is no longer able to access its child components. They all return null.

For example, I have a component called NumericLineEdit

extends HBoxContainer
class_name NumericLineEdit


@export var value:float:
	get:
		return value
	set(v):
		if value == v:
			return
		value = v
		dirty = true

var dirty:bool = true

# Called when the node enters the scene tree for the first time.
func _ready():
	pass # Replace with function body.


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if dirty:
		$TextEdit.text = str(value)
		
		dirty = false


func _on_text_edit_text_set():
	value = float($TextEdit.text)

If I run this alone, it works fine. But if I try to include it in another component, I get a bunch of errors about $TextEdit being null. I've tried using the % notation and also calling get_node(), but it's always null when I try to run a scene that uses it as a child.

nestedcomponent.zip
2MB
  • Toxe replied to this.
  • In the second screenshot it seems like your NumericLineEdit nodes are actually just that, nodes. Meaning there is no TextEdit child. You probably want to instantiate your NumericLineEdit scene instead.

    In the second screenshot it seems like your NumericLineEdit nodes are actually just that, nodes. Meaning there is no TextEdit child. You probably want to instantiate your NumericLineEdit scene instead.

    kitfox I just downloaded it and gave a look. It is as @Zini said, your nodes are just HBoxContainer nodes with your script attached but you are not using your NumericLineEdit scene. Your scene should look like this:

    Notice the little scene icons next to the script icons.