0 votes

Hello!

I've been reading in the Godot Docs about exporting variables
https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_exports.html
And noticed at the end of the page a section concerning adding Categories to the Script (as well as grouping exported variables (properties) together) and they give an example of it. I want to try out making my own category but even with the example, I don't know how to make the category appear or put exported variables/properties into the category. I find it weird that to make a category (or to group properties together) you need to use a function. How do you call the function to make a visible change to the inspector? How do you put variables into the section? I would be grateful for any help.

Here's the example on the Godot Docs

func _get_property_list():
    var properties = []
    properties.append(
        {
            name = "Debug",
            type = TYPE_NIL,
            usage = PROPERTY_USAGE_CATEGORY | PROPERTY_USAGE_SCRIPT_VARIABLE
        }
    )
    return properties
Godot version 3.2.1
in Engine by (71 points)

In order to make it visible in the Inspector it must belong to an object in the scene. So the above func getproperty_list(): must be attached via script to an object in the scene.

tool extends MeshInstance

func _get_property_list():
    print_debug("_get_property_list")
    return [
        {
            name = "MyProps/Debug",
            type = TYPE_BOOL,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },
        {
            name = "MyProps/Debug2",
            type = TYPE_BOOL,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        }
    ]

Of course you also should override _get and _set to handle the property path correctly and read from and assign to variables you want.

1 Answer

0 votes

Here you go. With some examples:

extends Node
tool

var first : int = 1
var second : int = 2
var ingroup_more : int = 3
var ingroup_numbers : int = 4
var half : float = 0.5
var quarter : float = 0.25

func _get_property_list() -> Array:
    return [{
            name = "Integers",
            type = TYPE_NIL,
            usage = PROPERTY_USAGE_CATEGORY 
        },{
            name = "first",
            type = TYPE_INT,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },{
            name = "second",
            type = TYPE_INT,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },{
            name = "Group",
            type = TYPE_NIL,
            hint_string = "ingroup_",
            usage = PROPERTY_USAGE_GROUP
        },{
            name = "ingroup_more",
            type = TYPE_INT,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },{
            name = "ingroup_numbers",
            type = TYPE_INT,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },{
            name = "Floats",
            type = TYPE_NIL,
            usage = PROPERTY_USAGE_CATEGORY
        },{
            name = "half",
            type = TYPE_REAL,
            hint = PROPERTY_HINT_RANGE,
            hint_string = "0.4, 0.6",
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        },{
            name = "quarter",
            type = TYPE_REAL,
            hint = PROPERTY_HINT_EXP_EASING,
            usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_SCRIPT_VARIABLE
        }]
by (1,524 points)
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.