It may be worth considering redesigning a bit, depending on what you're wanting to do. Let's say you want a Bullet to delete if it strikes a Mob. Let's say you've defined the function to do that in bullet.gd, and named it bullet_hit_mob
.
bullet_hit_mob():
print("Bullet hit something... deleting bullet")
queue_free()
When a Bullet enters a Mob, you've already got it set up to trigger the _on_Mob_body_entered
function in mob.gd. So in _on_Mob_body_entered
you can check if whatever collided with Mob is a bullet, and if it is you can call the bullet_hit_mob
function to delete the bullet:
_on_Mob_body_entered(body):
if body.is_in_group("bullet"):
print("Calling bullet_hit_mob on the bullet that hit this mob")
body.bullet_hit_mob()
To make this work you need to open up your Bullet.tscn and add it to a group named bullet. https://gyazo.com/320d2782b9af8eda0dad02620d19ed1c The reason we do that is because if something other than a Bullet collides with a Mob it won't have a function named bullet_hit_mob
so an error would occur. Like, if the Player collided with a Mob it would be wrong to try to call bullet_hit_mob
from Player.
One extra note. You could even get away without having any function in bullet.gd. You could delete the bullet from _on_Mob_body_entered
:
_on_Mob_body_entered(body):
if body.is_in_group("bullet"):
print("A bullet hit this mob. Deleting the bullet that hit this mob")
body.queue_free()
I hope this gives another perspective on how you could achieve similar results as you would if you used a signal to signal from the Mob to the Bullet that the Mob was hit. Please feel free to ask for further information or clarification.