How to add subcategories to the inspector "Script variables" section?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Matt_UV
:warning: Old Version Published before Godot 3 was released.

Hello, I have two objects in my scene (Some variables names are in French. Don’t worry, it doesn’t matter here :wink: ).

  • Joueur, which is the player. Its script is "res://Joueur/joueur.gd"
extends RigidBody2D

export(String, "LOCAL", "NETWORK", "AI") var type = "LOCAL"
export var vit_marche_max = 1200
export var vit_marche_min = 100
export var force_marche_sol = 1000
export var force_marche_air = 250
export var force_arret_sol = 300
export var force_arret_air = 100
export var val_saut = 700
export var duree_saut = .3
  • Joueur 2 which is an AI. Its script is "res://Joueur/AI.gd" and it inherits from the fist one
extends "res://Joueur/joueur.gd"
 
export var decision_delay = 1.5
export var aggressivity = 3

Thus, the inspector shows that :

(Note that the type of Joueur 2 has been manually modified from “LOCAL” to “AI”)

Here is my question: for Joueur 2, is it possible to separate the variables from the general script and the one from the inherited script?

There are subcategories for other elements, as the PhysicBody2D :

What I would like is something like this :

Do you know if this is possible ?
Thank you!

:bust_in_silhouette: Reply From: kubecz3k

This is not possible from the gdscript. It would be wise to create feature request on github page, since core developers are currently working on improving that kind of features (for plugin creation) and it’s great moment for such request: Issues · godotengine/godot · GitHub
EDIT: actually it’s possible, check Bojidar Marinov answer.

:bust_in_silhouette: Reply From: Bojidar Marinov

It is possible, though it isn’t easy. The basic idea is to override _get(), _set() and _get_property_list(). Also, since it has to run in the editor to display it, you need to use the tool keyword, and restart (at least in 2.0.2) every time you change that script’s editor logic.

Here is a simple example:

tool
extends Node2D

var test = "" # We will store the value here

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

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

func _get_property_list():
	return [
		{
 	 	 	"hint": PROPERTY_HINT_NONE,
 	 	 	"usage": PROPERTY_USAGE_DEFAULT,
 	 	 	"name": "test/test",
 	 	 	"type": TYPE_STRING
 	 	}
	]

Thank you very much!
That works really well, I will now see how to adapt it to my code.

Matt_UV | 2016-04-20 09:38

Can this be done in C#?
edit: yes!

override public Godot.Collections.Array _GetPropertyList(){
    var props = new Godot.Collections.Array(); 
    var enumstr =String.Join(",",Enum.GetValues(typeof(AiMovementType)));
    props.Add(PropEntry("HowToMove",Godot.Variant.Type.Int,Godot.PropertyHint.Enum,enumstr));
    return props;
}
public AiMovementType HowToMove;
public enum AiMovementType {XDir}
public static Godot.Collections.Dictionary PropEntry(string name,Godot.Variant.Type type, Godot.PropertyHint hint, string hintStr=""){
    var d = new Godot.Collections.Dictionary();
    d.Add("name",name);
    d.Add("type",type);
    d.Add("hint",hint);
    d.Add("hint_string",hintStr);
    return d;
}

And enums and such can be made by using PropertyHint

    //
    // Summary:
    //     Hints that an integer, float or string property is an enumerated value to pick
    //     in a list specified via a hint string such as "Hello,Something,Else".
    Enum = 3,

jarlowrey | 2021-03-21 00:59