Skip to content

Instantly share code, notes, and snippets.

@Shilo
Created April 1, 2024 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Shilo/e8d6cd7a6af1dcf3806fe1a76b4685ac to your computer and use it in GitHub Desktop.
Save Shilo/e8d6cd7a6af1dcf3806fe1a76b4685ac to your computer and use it in GitHub Desktop.
Godot 4 example on how to toggle @export visibility and readonly.
@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