#Is there a way to connect a signal from a scene dynamically created?

43 messages · Page 1 of 1 (latest)

night quail
#

I would like to emit a signal when my bullets hit an enemy, but that bullet is dynamically created and I was thinking about connecting that bullet's signal with a different ui node, but idk if what I want even makes sense lol

is there a way to achieve this somehow? or maybe doing it in an alternative way?

meager linden
#

can you get a reference to the ui from where you're creating the bullet?

night quail
#

good question gudthink

#

I think I can do something like get_node("../ui")

#

would it be a good idea?

#

but is there a way to connect my bullets with the ui without doing it manually through the signals section? the bullets are only created during gameplay @meager linden

balmy pelican
#

You can look at the "connect" call, it will connect signals programmatically:

var myBullet = <get a reference to the bullet>
myBullet.connect("signal", .......)

Look in the documentation, there is examples of this.

night quail
#

yeah, I was just reading about it, I think that will work

#

thanks

night quail
#

im trying to print a function about the name, but it gives me @CharacterBody2D@22:<CharacterBody2D#39107692062> lmao

balmy pelican
#

There are variaous ways, but without seeing how you create your bullets I don;t believe anyone can answer that.

#

That's it's name probably. If you are creating an instance , Godot will just give it a seemingly random name.

night quail
#

thats supposed to be the name of the thing it hit

#

for example this is one of the enemies, is there a way to get that Enemy1 label?

balmy pelican
#

You'll have to get it when it's instanced.

#

Or maybe I'm not following you.

night quail
#

thanks

#

I got the signals stuff working just fine

#

now its printing what my bullet hit, which in this case is that Enemy1, but I also have other enemies

#

but idk if I can differentiate if I hit one or the other

#

its only giving me the reference which doesnt tell me much

atomic sentinel
#

your code likely will

#

it doesnt do things based off of the name you dont have to worry about that

night quail
#

when I kill any of them

atomic sentinel
#

then you have two options i believe: just getting their name via enemy.Name or groups

#

do you know about the groups system

night quail
#

not really

#

was also trying to get the name, but it gives me some weird stuff

#

I was reading about unique names, but my character 2d doesnt have that option

atomic sentinel
#

you can go to the same panel where you connect signals, and click groups

#

you can add new groups to your nodes there

#

you can for example add a “StrongEnemy” group to a Strong Enemy and then use code to check the group and drop a certain amount of coins based on if it’s a strong enemy or not

night quail
#

thats interesting, im gonna do that then, seems to be a good solution gudthink

atomic sentinel
#

yeah its less fragile than hardcoded names

night quail
#

but anyways, im gonna do that thing about groups

#

thanks bro