How do I get a node from another scene in godot?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By BennieBe


I am trying to attach a node from another scene but somehow it does not work.
Can someone give me an example on how to do it?

I did it this way:
var bullet = get_node(“/root/BulletScene/Bullet”)

I always get null for the Scene Name.

:bust_in_silhouette: Reply From: denxi

get_node() is a function that pulls a reference to a node that’s already part of the scene tree. What you want is to instance a new object, with something like:

var bullet = preload("res://objects/bullet.tscn")

func add_bullet():
    var new_bullet = bullet.instance()
    add_child(new_bullet) #You don't need to preface this with "self"

For further info on what I’m assuming the next issue you’ll run into will be, take a look here: Instancing with signals — Godot Engine (stable) documentation in English


Yes, this is what I seek, thanks a lot!

BennieBe | 2020-05-31 16:47