Godot 4 – Keep Your Inspector Clean with @export_group

If you have properties in a script that you will tweak a lot, you might know how to use @export to make that property available in the Inspector.

To improve the experience even more, have you given @export_group a try yet? This lets you sort your exported properties into groups in the editor – keeping things neat and tidy.

Check out this example: My project that has characters randomly wander around the level.

I’ve set things up so that I can use the Inspector to design a chance that the character will take a break for a few seconds and stop moving:

Here’s the result in Godot:

A side by side of Godot 4 code using @export_group to sort properties into groups with an image of the final groups shown in the Godot 4 Inspector
Easy to use, in particular if someone might edit the properties without looking at the script.

Detailed Explanation

@export_group("Group Name")Starts a new group.

All properties below this line will be sorted into this group until you define a new one.
@export_subgroup("Subgroup Name") Starts a new subgroup. It will be a subgroup of the @export_group above it.

You can only nest one level of subgroups.
@export_group("Group Name", "prefix")You can optionally specify a prefix for any group or subgroup as the second argument.

If you do, the prefix will be removed from the property names in the Inspector.

This trick can keep things a lot cleaner to read in a narrow Inspector. See how much space is saved above by removing the "break_" from every property name?

You can maintain the clarity of the property name in a large script without sacrificing the editor experience.

Do your future self a favor and give this a try in your next script with exported properties!

Leave a comment

A WordPress.com Website.