Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | imekon | |
Old Version | Published before Godot 3 was released. |
onready var red = get_node("red")
onready var green = get_node("green")
onready var blue = get_node("blue")
red, green and blue are children of the current node, yet they are null when get_node is called?
main.gd:
onready var _factory = load("res://scenes/blockfactory.tscn")
var factory = _factory.instance()
if factory == null:
print("no factory!")
return
var block = factory.createRed(100, 100)
if block == null:
print("no red")
return
add_child(block)
_factory is fine, but createdRed fails
blockfactory.gd:
func createRed(x, y):
if red == null:
print("no red")
return null
var block = red.duplicate()
if block == null:
print("no block")
return null
block.set_pos(Vector2(x, y))
return block