#Help recreating this enable/disable editor functionality

10 messages · Page 1 of 1 (latest)

waxen bolt
#

I would like to make some exported variables disappear unless an exported boolean is set to true. I want to know how you could reproduce it as seen in the world environment node in a tool script. Godot 4.X

quasi atlas
#

look up the _get_property_list function. I think its example is exactly this

waxen bolt
#

here are two examples. On the left is a script written for godot 3 that i updated to godot 4's requirements, and on the right is the godot 4 documentation example which i converted for godot 3

#

Neither work in godot 4.1.1. Both work in 3.5.2

#

(notice how the outline property and the hammer type property are missing on godot 4 but not on 3.5.2)

#

here is the code for the 3.5 version of the hammer thing in case you want to verify this

#
tool
extends Node2D

export var holding_hammer = false setget setf
    
var hammer_type = 0

func setf(value):
        holding_hammer = value
        property_list_changed_notify()

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

    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```
#

the godot 4 version is in the docs of _get_property_list ^