0 votes

Hi all,

I have a heap of HUD items showing lives, ammunition etc. I have my bullets all shown and I want to remove the last ones in the group.

They are in group called HUDbullets. How can I find one to remove it in code? Thank you.

(Godot 3.0)

in Engine by (825 points)

1 Answer

+2 votes
Best answer

SceneTree.get_nodes_in_group("group_name") returns an array containing the nodes in a group. So you could assign it to a variable, like such

var nodes = get_tree().get_nodes_in_group("HUDbullets")

and then use the Array methods to pick the right ones.

by (563 points)
selected by

Hey thanks for that. I have been digging and have:

var results = []
    for node in get_tree().get_nodes_in_group("HUDBullets"):

I guess I now need to find the last in an array and then queue_free() it. I had a read at docs.godotengine.org/en/3.0/classes/class_array.html I found back() and gave it a whirl like so:

#create array
var results = []
#stuff the bullets into the array
for node in get_tree().get_nodes_in_group("HUDBullets"):
#delete the last bullet in the array
if results.back():

So hopefully that helps someone in the future and thanks so much to /u/Dodolta It's really appreciated.

You're welcome.
Good luck with your game.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.