0 votes

I'm building breakout. So i have multiple balls that can spawn/instance.

I want to send a signal from the ball, when it's time to remove a brick. The problem is, there are multiple ball instances and each with different names.

In ball.gd I use emit_signal("destroyBrick")

So in the brick.gd file, if I try and use: ball.connect("destroyBrick", self, "destroyThisBrick") it won't work as ball changes its name each time it's added to the scene.

Does anyone know how to use a signal when the receiving node doesn't know the name of the emitting node?

in Engine by (810 points)

2 Answers

+1 vote
Best answer

You really just need to check body_enter on the ball, and see if the body has destroyThisBrick, if so, destroy it.

connect("body_enter", self, "destroy_brick")

func destroy_brick(body):
    if (body.has_method("destroyThisBrick")):
       body.destroyThisBrick

Responding you other question too, in the brick you need to just

func destroyThisBrick():
   numOfHitsRequired--

   if numOfHitsRequired <= 0:
      #code
by (1,082 points)
selected by

Thank you for that. It solved the problem. For those in the future I did have to add the get_parent() part as below:

if (entity.get_parent().has_method("destroyThisBrick")):
    entity.get_parent().destroyThisBrick

Thanks again, much appreciated.

+1 vote

just guessing here.
1.maybe you create a node with a known name add ball instances to this node and then use: get_children() to find the names of all instances.
2. after creating the instance, use: ball.set_name("ball" + str(ball.get_instance_ID), store names in an array for later use.
Anyway interesting to see how you solve this.

by (518 points)
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.

Categories