How to add custom description to properties from _get_property_list()?
Asked Answered
T

6

0

Is it possible to add custom description to properties from _get_property_list() to show it as a tooltip (instead of "No description")?

Tessy answered 23/1, 2023 at 14:51 Comment(0)
P
0

Not sure about godot 3, but you've tagged as godot 4 anyways, so looking at the docs:
https://docs.godotengine.org/en/latest/classes/class_object.html#class-object-method-get-property-list

the example included there:

@tool
extends Node2D

@export var holding_hammer = false:
    set(value):
        holding_hammer = value
        notify_property_list_changed()
var hammer_type = 0

func _get_property_list():
    # By default, `hammer_type` is not visible in the editor.
    var property_usage = PROPERTY_USAGE_NO_EDITOR

    if holding_hammer:
        property_usage = PROPERTY_USAGE_DEFAULT

    var properties = []
    properties.append({
        "name": "hammer_type",
        "type": TYPE_INT,
        "usage": property_usage, # See above assignment.
        "hint": PROPERTY_HINT_ENUM,
        "hint_string": "Wooden,Iron,Golden,Enchanted"
    })

    return properties

Shows that "hint_string": "string of text here" could be used.

Prochronism answered 23/1, 2023 at 15:40 Comment(0)
T
0

My doubt is about Godot 4 haha

What I want to change is the editor description of the property (tooltip). Instead of "No description.", I want to put a custom description text (example: "This is my property!").
hint_string is the field used to specify parameters of hint (like range, enum or filetype), not for descriptions.

Tessy answered 25/1, 2023 at 14:11 Comment(0)
P
0

In that case I know of no way of doing so. There was an addition made for having an editor description for nodes, but not for individual properties afaik.

Prochronism answered 25/1, 2023 at 21:58 Comment(0)
M
2

I'm not sure I fully understand what you're talking about, but it seems to me that you're looking for a way to give the @export variables in editor descriptions.

If I understand correctly the solution is simple, just use the ## comment above the variables you want to document. It also works for node description.

## Node Description 
extends Node2D

## This is my property!
@export var myProperty : bool

Note that the ## method works on all types of script not just in @tool one, so you don't need the
_get_property_list(), this of course only applies to descriptions. In addition Godot 4 sometimes does not take the description immediately, if you have any problems I suggest restarting the engine.

If you for some reason instead really want to use _get_property_list()
to add descriptions then I can't help.


Mancuso answered 11/4, 2023 at 19:47 Comment(0)
A
0

Mancuso I think this is what OP was looking for because this is exactly what I was looking for, thank you!

Ay answered 30/9, 2023 at 22:2 Comment(0)
R
0

Mancuso
That is what I need exactly🥰

Reichel answered 22/3 at 12:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.