0 votes

Say there's a function that instances a scene into the main scene.

func shoot(args):
var projectile = preload(path).instance()
projectile.position = (formula for calculating position)
projectile.velocity = (formula for calculating velocity)
$background.addchild(projectile)

however, i also need to reach a child of the projectile node, Area2D, to connect its body entered signal to the main scene. Is there a way to do it before adding the child, or do i have to do it after using $background.getnode()?
Godot version 3.2.3
in Engine by (72 points)

1 Answer

+1 vote
Best answer

After you instantiated the projectile you can do it whenever you want really.
Like this for example:

func shoot(args):

    var projectile = preload(path).instance()

    #connect the signal
    projectile.get_node("path to Area2D").connect("singal", object, "function name")

    projectile.position = (formula for calculating position)

    projectile.velocity = (formula for calculating velocity)

    $background.addchild(projectile)
by (254 points)
selected by

Thanks! I'm really stupid that i didn't think of using get_node() on the var.

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.