0 votes


I am trying to instantiate a Bullet Node in another Scene. I want this because I want to separate the Bullet Scene from any other Scene and only instantiate it in a Scene when a certain Signal occurs. I tried to follow this example:

Unfortunately, it is not possible to use the Node tab to connect Signals because the Scene which emits the Signal does not see the other Scene where it should connect to.

I read that I can do it programmatically, something like this: bullet.connect("shoot", self, "onPlayer_shoot")

But this does not work for me somehow.

This is my Bullet Script from one Scene:

extends Node2D

signal shoot(bullet, direction, location)

onready var bullet = load("res://Scenes/Bullet.tscn")

func _input(event):
    if event is InputEventMouseButton:
        if event.button_index == BUTTON_RIGHT and event.pressed:
            emit_signal("shoot", bullet, rotation, position)

func _process(delta):

I want to connect it to a Player Node in another Scene, I tried something like this
in the Player.gd script which doesn't work

onready var bullet = preload("res://Scripts/Battle/Bullet.gd")

func _ready():
    bullet.connect("shoot", self, "_on_Player_shoot")

func _on_Player_shoot(bullet, direction, location):
    var b = bullet.instance()
    b.rotation = direction
    b.position = position
    b.velocity = b.velocity.rotated(direction)

What do I need to do here to make this work? Is there a better way than doing it programmatically like this?

in Engine by (29 points)

1 Answer

0 votes

Connect the signal after you instance the bullet

edit: also I think you want to instance bullet.tscn instead of .gd

by (267 points)

I am not sure how this works? Would you mind providing an example?
I tried out different ways, I am not able to get it to work ...

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.