How to export variables with a setter by overriding _get_property_list()?

Godot Version



I am trying to make a very well organized “Player Variables” section in the inspector of my player scene in my game. It should be structured like this:

  • Grounded Movement (group)

    • Instant Grounded Movement (boolean)
    • some more variables
  • Air Movement (group)

    • Instant Air Movement (boolean)
    • some more variables

The Instant Grounded Movement variable, when toggled on, should make the other variables in the Grounded Movement group after it disappear (same thing for Instant Air Movement). To do this I override _get_property_list() and return an Array of Dictionaries that represent the variables that might be hidden or not depending on the state of Instant Grounded movement. This works pretty well until now but I have encountered a problem that can easily be described in the following image:

hehe my godot is green

In _get_property_list() I put all the variables inside of a category called “Player Variables” because otherwise it doesn’t look good. I also put Instant Grounded movement in a category of the same name but it is exported using @export annotation and it does not show up in the same category. I would very much like to export Instant Grounded movement using _get_property_list() but there needs to be a setter function for this variable and I do not know how do that!

Here’s my Instant Grounded movement variable:

@export var instant_grounded_movemement: bool = false:
		instant_grounded_movemement = value

Summing up the question

How do I export a variable using _get_property_list() and make it so that variable has a setter function that gets called every time it gets changed through the editor?

Thanks a lot to anyone who would give me advice on this!

Don’t use @export in the variable and it should call the setter. If it does not do that then you can try using Object._set() as the setter.

Thank you so much! I just removed @export from the variable declaration at the top and added it in _get_property_list():

		"name": "instant_grounded_movemement",
		"type": TYPE_BOOL,

(Hope this can help anybody who encounters a similar problem!)