Cannot get all instances with scene's name

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By dancaer69

I have 5 preloaded scenes and I have generate 3 instances of each.
I’m trying to get the 3 instances for one of them by the name but I get only one.

func check_inst():
    var scene_array = []
	var red_inst=[]
	for item in self.get_children():
		if item.get_class() == "Sprite":
	for i in range(scene_array.size()):
		if scene_array[i].name == "RedCircle":

The scene_array outputs all 15 instances, but the red_inst prints only one of the three. Am I doing something wrong?

If I print an array with all instances are 15, so in the array

:bust_in_silhouette: Reply From: Inces

Name is unique variable for every instance. First name is Sprite, but next ones get names Sprite02 and Sprite03. Instead You can use

is_class("Sprite") == true.

For scripts You can use class_name, for custom scenes - filename.

Thanks, I thought about this too, so I tried also to use “RedCircle1” before post here which didn’t work.
Now I tried with 02 but again I get an empty array. The name of the sprite in scene is RedCircle. If I check with this name I get an 1 item array. If I check about RedCircle01 or RedCircle1 I get an empty array

dancaer69 | 2021-03-30 16:59

So what is red circle ? Is it a scene You created based on Sprite ? If so, than all instances of this scene will share common FILENAME, at least if You loaded them from code. FILENAME is a string containing resource path, so maybe You can use it for checking instead of NAME.

If You insist on calling NAME, then You can test what exactly are those names spelled with print(), or simply running your project and viewing nodes in remote tab. Usually they contain some @sign.

Inces | 2021-03-30 17:10

RedCircle is a scene which contains a sprite with name RedCircle, the same the other 4 scenes.
I’ll try without using name.

dancaer69 | 2021-03-30 17:26