Need help with this please

Godot Version

4

Question

i have a script to check if the Child is named “Inventory_Item” but when i duplicated the item it says “Inventory_Item2” and the script will not work for both of them, is there a way i can check if the name is “Inventory_Item” without the number 2?

yes:

if child.name.begins_with("Inventory_Item"):
    # your code here
1 Like

Thank you!

How would i get the child though? i have multiple in one node and im using the “Inventory_Item” name to find it.

When you have access to this one node you can call the get_children()-method:

for child in node.get_children():
    if child.name.begins_with("Inventory_Item"):
         # Do something

You can also use other ways to check children:

for child in node.get_children():
    if child is InventoryItem:
         # Do something

In this case your InventoryItem needs to have a class_name called “InventoryItem”

1 Like

it worked, Thank you!

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.