Created
April 1, 2024 03:53
-
-
Save Shilo/e8d6cd7a6af1dcf3806fe1a76b4685ac to your computer and use it in GitHub Desktop.
Godot 4 example on how to toggle @export visibility and readonly.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tool | |
extends Node2D | |
@export var show_number: bool = false: | |
set(value): | |
show_number = value | |
notify_property_list_changed() | |
@export var editable_number: bool = false: | |
set(value): | |
editable_number = value | |
notify_property_list_changed() | |
@export var number: int = 0 | |
func _validate_property(property: Dictionary) -> void: | |
if !show_number: | |
if property.name == "number" || property.name == "editable_number": | |
property.usage ^= PROPERTY_USAGE_EDITOR | |
elif !editable_number: | |
if property.name == "number": | |
property.usage |= PROPERTY_USAGE_READ_ONLY |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment