Hello, I am trying to iterate on each child, and for each child I want to check if it has a specific script attached.

My current code is something like this:

for child in get_children():
    var child_script = child.get_script()
   # do check for script name here...

How to check if name of child_script is for example "lasercannon.gd" or similar. I have tried, child_script.name, child_script.get_name(), typeof(child_script) etc but nothing works.

I did try to look things up in the API, and later search the forums but found nothing.

Have you tried:

if child_script == preload("lasercannon's path.gd"):

Apparently, according to this Reddit post, you can use get_path on the returned script from get_script to get the path to the script, which then can be used to get the script’s name.

Though @SIsilicon28’s method is probably a better way to handle if it works for your project.

3 years later