0 votes

Greetings! Thanks in advance for reading this!

I'm making a small game and I've been leaning pretty heavily on groups for making set pieces, tilemaps and enemies visible/invisible as my level demands it. It's an awesome feature and a huge convenience for me.

Right now I'm working on a function that will refresh the UI whenever the player gets an upgrade that would warrant adding an icon/item to the HUD (this is a Metroidvania, so upgrades would be far apart). Since the GUI is made of several items, I was thinking of making things easier on myself and using call_group on a "UI" group that will tell every UI element to refresh itself. I'm not familiar with how groups work under the hood, and I'm not sure if that's a waste of resources. I could write each upgrade manually (the upgrade method finding and activating the required HUD element specifically instead of this general solution), but I don't want to waste time if I don't have to.

Is call_group a reasonable solution to this?

in Engine by (158 points)

1 Answer

+1 vote
Best answer

I don't want to waste time

Then stop worrying! If this becomes an issue, you're definitely doing something wrong.

I'm not familiar with how groups work under the hood

You can find the relevant function here. It uses a map-structure to look up which group-object is associated with the group-name, then loops over all the nodes associated with that group and calls the function. No black magic involved.

by (10,315 points)
selected by
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 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.