When should I use groups and @export?

I’ve finished 2 project in Godot 3D course, the Project Boost and Barbarian Blaster. But I still confuse when should I use groups and @export when I have to access scenes in scripts. Maybe I’m missing something. Thank you

In some cases, they can do the same job, but they’re really meant for different purposes. You can use them to check if an object scene belongs to the group and then perform logic based on that result. This is just like checking if something is class_name, but groups are not limited to one name per class, nor are those multiple groups mutually-exclusive. That opens up a lot of possibilities! You can also iterate over a group to do something to all members of that group, forming the backbone of any automation needs in your projects.

@export variables can be used for a lot of different referencing situations, but this makes it easy to abuse them. In many cases, something else just does the job better (when @export isn’t needed, you probably want to use @onready instead for example). Where @export really shines is when you place multiple object instances during designtime and you want them to be individually configurable, because @export basically extends the instance’s Inspector with new properties. Want some of those 10 bandits to have different starting health / max health values? Done. Different speeds or jump heights? No problem. For anything like this, @export is absolutely indispensable because those customizations are harder to make without them.

There’s more I could mention, but this should give you a good idea of where you would want to use each =)

2 Likes

Okay, thanks for the explanation. I’m starting to understand the different conditions in using it. I’m sure I’ll understand more if I keep learning. Thanks again

1 Like

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

Privacy & Terms