0 votes


I've got a node in my scene tree which generate some instances of my scene programmaticaly (the Player for example) .

I also have a camera node in my scene tree and it needs to connect some specific instances to this camera by using getnodesin_group method. But when my camera script gets the nodes in group "shake screen" for example, there is nothing, as the instances are not yet instancied. So the nodes are not connected and then i can't use signals properly.

I don't know if this is a problem in the way i structure my projet or if i'm missing something in the way to instantiate/load nodes.

in Engine by (14 points)

1 Answer

0 votes

Hey Llenucs,
I don't know when you are create the instances. You should keep in mind that the _ready() function is done from bottom to top in your tree, from child to parent. Don't know how your structure looks, but this could be one problem. On the other hand you could just call the cameras connect_to_nodes()function each time you add a new node. Like this:

# Camera-Script
func  connect_to_nodes():
    for node in get_tree().get_nodes_in_group("Players"):
        connect("shake", node, "do_shake")

# Another script
func instance_scene():
   var new_scene = Myscene.instance()

The problem is that this would reconnect all nodes over and over again. So it's not that useful and I would recommend to just connect the nodes when they are instanced:

func instance_scene():
    var new_scene = Myscene.instance()
    get_node("SomeNode/MyCamera").connect("shake",new_scene, "do_shake") 

Is this what you were looking for or did I understand you wrong?
Good luck,


by (864 points)

You understand well ;)

And yes i ended up with your solution which is the best I think.

In fact i first tried to avoid calling node explicitely with getnode("mynode") in case the structure will change, because i thought it was a best solution to use groups to connect nodes, which allow to redefine node's hierarchy.

But yes your solution works fine, thank you :)

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 Frequently asked questions and 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 [email protected] with your username.