Is there a way to add exported variables to a group?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mateusak

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?

:bust_in_silhouette: Reply From: jovansystem

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.

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

https://forum.godotengine.org/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()

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

hedin_hiervard | 2018-11-21 12:08