Is it possible to export/expose variables conditionally?

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

I want to expose or hide variables based on choices in the editor.

Something like this:

export var moving = true
if moving:
    export var speed = 200
:bust_in_silhouette: Reply From: ywaby

use

_get_property_list()

https://forum.godotengine.org/3196/how-add-subcategories-inspector-script-variables-section

example:

tool
extends Spatial

var list_abc = true 
var abc = "123" 

func _get(property):
    if property == "group/subgroup/abc":
        return abc 
    if property == "group/list_abc":
        return list_abc        

func _set(property, value):
    if property == "group/subgroup/abc":
        abc = value
    if property == "group/list_abc":            
        list_abc = value  
        property_list_changed_notify()# update inspect
    return true

# call once when node selected 
func _get_property_list():
    var property_list = []
    property_list.append({
        "hint": PROPERTY_HINT_NONE,
        "usage": PROPERTY_USAGE_DEFAULT,
        "name": "group/list_abc",
        "type": TYPE_BOOL
    })
    if list_abc==true:
        property_list.append({
            "hint": PROPERTY_HINT_NONE,
            "usage": PROPERTY_USAGE_DEFAULT,
            "name": "group/subgroup/abc",
            "type": TYPE_STRING
        })     
    return property_list

ywaby | 2018-12-06 05:52

What should I use as “type” for an array of enum values? If I’m just exporting normally I would just use:

export (Array, MyEnum) var enum_array

How would I do this with this method?

dopey_kun | 2021-07-19 08:21