• General Chat
  • Is there a way to get the scene name from its instance?

Here is my situation:

I have a main scene contains display panel, music, and many enemy nodes. I want to get all enemy nodes and do something to them.

I do some google work and get this:

for _i in self.get_children():
    if _i.get('ID') != null:
        print('Check all %d' % _i.ID)

I iterate all children and get all enemy nodes by a identical variable 'ID'.Just the enemy nodes have 'ID' property. It works fine now. But the way to do this is a little ugly I think. Since when other nodes added to main scene also with the ID property, it will cause a error. Of course I can add a name property to enemy node with an unique name value.

But I think if I can get the scene name of one instance will be more elegant in this case. I think.

You can check the node's class like in the test project.