You can use Object._validate_property()
to modify an exported variable.
Here’s an example:
@tool
extends Node
enum Area { Area1, Area2 }
enum Room { Room1, Room2, Room3, Room4 }
@export var area:Area:
set(value):
area = value
notify_property_list_changed()
@export var room:Room
func _validate_property(property: Dictionary) -> void:
if property.name == "room":
match area:
Area.Area1:
room = Room.Room1
property.hint_string = "Room 1:0,Room 2:1"
Area.Area2:
room = Room.Room3
property.hint_string = "Room 3:2,Room 4:3"
func _property_can_revert(property: StringName) -> bool:
if property == "room":
# room default value depends on the area so we need to use a custom revert value
return true
return false
func _property_get_revert(property: StringName) -> Variant:
if property == "room":
# return the default value depending on the area
match area:
Area.Area1:
return Room.Room1
Area.Area2:
return Room.Room3
return null
You can get more information here about what the property
dictionary should contain and how to fill it by checking the Object.get_property_list()
documentation.