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:
@export_group("Movement")
@export var wandering := false
@export var speed : int = 200
@export var reverse := false
@export_group("Take Breaks", "break_")
@export var break_disabled := false
@export_range(0,100) var break_chance : float
@export var break_max : float
@export var break_min : float
@export_subgroup("Active Break", "break_")
@export var break_active := false
@export var break_time_remaining : float = 0
Here’s the result in Godot:
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