0 votes

i'm trying to instance the bullet scene instead the main scene and i'm having this error:
parent node is busy setting up children, addnode() failed. Consider using calldeferred("add_child", child) instead.

the script is attached to the player node, direct child of the scene node.

func _ready():
    var bulletscene = load("res://scenes/bullet.tscn")
    var bullet = bulletscene.instance()
    get_node("/root/level").add_child(bullet)
    set_process(true)
    set_process_input(true)
in Engine by (27 points)

1 Answer

+4 votes
Best answer

You should do what the error is suggesting.
get_node("/root/level").call_deferred("add_child", bullet)

Nodes don't want to add any new children until it's ready. A node isn't ready until all its children are ready.

call_deferred takes the function&arguments you give it and puts off calling it until the next process cycle; by then, all the initial nodes in your scenetree should be ready.

by (1,328 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.