Scene elements are still null inside _ready()

Godot 4.4.1

class_name MapTile

extends Control

func _ready() -> void:
	var flowContainer = $MapTile/PanelContainer/CenterContainer/VFlowContainer
	print(flowContainer)

flowContainer is null but it shouldn’t be?

Hi,

Path should be $PanelContainer/CenterContainer/VFlowContainer if the script is already attached to MapTile.

1 Like

I’ve tried with that change already and it doesn’t work.
This is how the node is used elsewhere in the project:

func _ready() -> void:
	var tile = MapTile.new(foodList)
	$PanelContainer/ScrollContainer/Map/AllFood.add_child(tile)

Any other context I can give that might be useful?
I’ve stripped it down to just print($PanelContainer) and it still prints out a null object

image
Well it works fine on my side with the same exact setup so I’m not sure what could be happening here.
Have you attached the same script somewhere else, where the tree is not the same? @hyvernox answer is actually right so don’t bother answering my question.

MapTile.new() creates a new MapTile object that does not have any child nodes. You need to instantiate the scene instead.

3 Likes

Thank you that fixed the problem.
I replaced that code with add_child(preload(“res://my_scene.tscn”).instantiate().with_data(data))

1 Like