+5 votes

For example, the sprite node has this piece of code:

ADD_GROUP("Region", "region_");

enter image description here

Which creates the Region group, with it's child variables Enabled, Rect and Filter Clip

Is there a way to accomplish a similar result using GDScript?

in Engine by (1,106 points)
edited by

1 Answer

+4 votes

Hi, as far as I can tell, in 3.0 there is no simple way to do this, although there seems to have been some discussion about adding this functionality.

https://github.com/godotengine/godot/pull/10303
https://github.com/godotengine/godot/issues/4378

It is possible, though, as described by Bojidar Marinov in a post to this thread:

https://godotengine.org/qa/3196/how-add-subcategories-inspector-script-variables-section

Here is a slightly different implementation I use based on the same technique:

Scripts/PropertyList.gd

extends Object

var properties = {}

func add(name, type, default_value):
    properties[name] = {
        "hint": PROPERTY_HINT_NONE,
        "usage": PROPERTY_USAGE_DEFAULT,
        "name": name,
        "type": type,
        "value": default_value 
    }

func get(name):
    return properties[name].value

func set(name, value):
    if properties.has(name):
        properties[name].value = value

func _init(list):
    for prop in list:
        add(prop[0], prop[1], prop[2])

And then, in your scripts you can do:

tool
extends Spatial

const PropertyList = preload("res://Scripts/PropertyList.gd")

var property_list = PropertyList.new([
    ["test/foo",TYPE_STRING,"allo"],
    ["test/bar",TYPE_INT,32],
    ["other/foo",TYPE_STRING,"truc"],
    ["other/bar",TYPE_INT,8]])

func _get(property):
    return property_list.get(property)

func _set(property, value):
    property_list.set(property, value)

func _get_property_list():
    return property_list.properties.values()
by (22 points)
edited by

Is it possible to set the type as Texture this way?
Like the TexturedButton groups it's textures under Textures category?

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 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 webmaster@godotengine.org with your username.