0 votes

In Godot 3.x, it was easy to add properties and property categories by overriding _get_property_list().

The following example, based on the docs, will show the test property in Godot 3.4.3 inspector when the following script is attached to a node:

class_name PropTest extends Node

var test:int = 10 # We will store the value here

func _get(property):
    if property == "my_property":
        return test # One can implement custom getter logic here

func _set(property, value):
    if property == "my_property":
        test = value # One can implement custom setter logic here
        return true

func _get_property_list():
    var properties = []
    # Same as "export(int) var my_property"
        name = "my_property",
        type = TYPE_INT
    return properties

If I try the exact same code in Godot 4 (adding @ before tool), it doesn't update the inspector. The _get_property_list method does get called, easily visible by adding a print call, but the property doesn't show in the inspector.

The latest docs has changed, and removed this exmaple. Is it no longer possible to do this with GDScript?

Godot version 4.0.alpha
in Engine by (12 points)

i would also like to know the answer to this question, as my properties are no longer exporting in the most frustrating way after attempting to port

1 Answer

+1 vote

func getpropertylist() still works the same as before.

var subdivision: int = 1
var subdivisions_array = []
var subdivisions_hint = ""

func _get_property_list():
    var props = []
    props.append({name="subdivision", type=TYPE_INT, hint=PROPERTY_HINT_ENUM,
        hint_string=subdivisions_hint, useage=PROPERTY_USAGE_DEFAULT}
    return props

But set and get are different now, more like this:

@export var mesh_size: int = 5120:
        mesh_size = new_size

See the new documentation here for set and get: https://docs.godotengine.org/en/latest/tutorials/scripting/gdscript/gdscript_basics.html#properties

by (34 points)
edited 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 Frequently asked questions and 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 [email protected] with your username.