Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | TheNewGrant |
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
In order to make it visible in the Inspector it must belong to an object in the scene. So the above func _get_property_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.
5pectre7 | 2021-11-21 21:41