• Godot Help
  • How I can highlight sections with script variables in inspector

Hello, dear Community! Unity has the ability to highlight and separate variables in the inspector. How I can make the same things in Godot?
preview from unity

    • Best Answerset by evg

    I got the answer in discord community of GDQuest from user Razoric
    And I want to save it here

    In godot 4, this is easily accomplished through categories, groups, and sub-groups annotations

    extends Node
    @export_group("Stats")
    @export var hp := 100
    @export var rot_speed := 20
    @export var dodge_speed := 20
    @export var dodge_decrementor := 0.75
    
    @export_group("Truth")
    @export var can_move := true
    @export var allow_right_strike := true
    @export var am_preoccupied := false

    In godot 3.x, it's also possible to do this, but you need to use the _get_property_list function and make your script a tool script.

    tool
    extends Node
    
    var hp := 100
    var rot_speed := 20
    var dodge_speed := 20
    var dodge_decrementor := 0.75
    
    var can_move := true
    var allow_right_strike := true
    var am_preoccupied := false
    
    
    func _get_property_list() -> Array:
        return [
            {
                "name": "Stats",
                "type": TYPE_NIL,
                "usage": PROPERTY_USAGE_GROUP,
            },
            {
                "name": "hp",
                "type": TYPE_INT,
            },
            {
                "name": "rot_speed",
                "type": TYPE_INT,
            },
            {
                "name": "dodge_speed",
                "type": TYPE_INT
            },
            {
                "name": "dodge_decrementor",
                "type": TYPE_REAL
            },
            {
                "name": "Truth",
                "type": TYPE_NIL,
                "usage": PROPERTY_USAGE_GROUP,
            },
            {
                "name": "can_move",
                "type": TYPE_BOOL
            },
            {
                "name": "allow_right_strike",
                "type": TYPE_BOOL
            },
            {
                "name": "am_preoccupied",
                "type": TYPE_BOOL
            }
        ]

    You can use export_category or PROPERTY_USAGE_CATEGORY instead, too, for a different look.

    • @export_group and PROPERTY_USAGE_GROUP will put all subsequent variables inside of a collapsible section until there is a new group or category to replace it
    • @export_subgroup will put all subsequent variables inside of a collapsible section that is itself part of the previous group. Godot 4 only (there is no PROPERTY_USAGE_SUBGROUP in Godot 3)
    • @export_category and PROPERTY_USAGE_CATEGORY will put all subsequent variables inside of a categorized view that can't be collapsed

You can in Godot 4.0. 3.x does not have the ability.

@export_category("Info")
@export var title : String = "A Box"
@export var color : Color = Color.LIGHT_CORAL
@export_category("Physics")
@export var speed : float = 0.0
  • Edited
  • Best Answerset by evg

I got the answer in discord community of GDQuest from user Razoric
And I want to save it here

In godot 4, this is easily accomplished through categories, groups, and sub-groups annotations

extends Node
@export_group("Stats")
@export var hp := 100
@export var rot_speed := 20
@export var dodge_speed := 20
@export var dodge_decrementor := 0.75

@export_group("Truth")
@export var can_move := true
@export var allow_right_strike := true
@export var am_preoccupied := false

In godot 3.x, it's also possible to do this, but you need to use the _get_property_list function and make your script a tool script.

tool
extends Node

var hp := 100
var rot_speed := 20
var dodge_speed := 20
var dodge_decrementor := 0.75

var can_move := true
var allow_right_strike := true
var am_preoccupied := false


func _get_property_list() -> Array:
    return [
        {
            "name": "Stats",
            "type": TYPE_NIL,
            "usage": PROPERTY_USAGE_GROUP,
        },
        {
            "name": "hp",
            "type": TYPE_INT,
        },
        {
            "name": "rot_speed",
            "type": TYPE_INT,
        },
        {
            "name": "dodge_speed",
            "type": TYPE_INT
        },
        {
            "name": "dodge_decrementor",
            "type": TYPE_REAL
        },
        {
            "name": "Truth",
            "type": TYPE_NIL,
            "usage": PROPERTY_USAGE_GROUP,
        },
        {
            "name": "can_move",
            "type": TYPE_BOOL
        },
        {
            "name": "allow_right_strike",
            "type": TYPE_BOOL
        },
        {
            "name": "am_preoccupied",
            "type": TYPE_BOOL
        }
    ]

You can use export_category or PROPERTY_USAGE_CATEGORY instead, too, for a different look.

  • @export_group and PROPERTY_USAGE_GROUP will put all subsequent variables inside of a collapsible section until there is a new group or category to replace it
  • @export_subgroup will put all subsequent variables inside of a collapsible section that is itself part of the previous group. Godot 4 only (there is no PROPERTY_USAGE_SUBGROUP in Godot 3)
  • @export_category and PROPERTY_USAGE_CATEGORY will put all subsequent variables inside of a categorized view that can't be collapsed
evg changed the title to [Solved] How I can highlight sections with script variables in inspector .
Megalomaniak changed the title to How I can highlight sections with script variables in inspector .

@evg instead of changing the title please press the 'select best answer' under a relevant comment. 👍