_validate_property and instant auto-updating of folder names

Godot Version

v4.3.beta2.official [b75f0485b]

Background (in case it might help anyone)

I have a resource (class_name = SomePlace) that has three properties, all of them Strings.
continent, country, city

The values that are valid for these properties are just the names of folders in my directory tree. This is an example path :

I wanted to work within the inspector quickly, so I made the resource a tool resource, by adding the one simple line at the top:

Then, I added this function in the resource:

func _validate_property(property: Dictionary) -> void:
	var hintstr : String = ""
	var fowlder : String = ""
	if property.name == "continent":
		fowlder = "res://continents/"
	if property.name == "country":
		fowlder = "res://continents/"+continent+"/"
	if property.name == "city":
		fowlder = "res://continents/"+continent+"/"+country+"/"
	if DirAccess.dir_exists_absolute(fowlder):
		for foldername in DirAccess.get_directories_at(fowlder):
			hintstr += foldername + ","
	hintstr += "any value is fine," 
	property.hint = PROPERTY_HINT_ENUM
	property.hint_string = hintstr

So now, when I make a new resource, or I collapse and then expand the resource, it basically makes little drop-down menus for me to select the folders I want to use.


When I select a value in one of those wonderful dropdowns, it doesn’t then immediately make it so I can select the next “size” property. I have to first collapse and then expand the resource for the properties to all load their list of folders. (I can see that it is calling the _validate_property function for every property in the resource, twice for some reason.)


How do I make the relevant properties in the resource call the _validate_resource function when I select a value? (e.g. When I select a value for “continent” I want the resource to populate the field for “country” by running the validate_property function, since a new set of folders would be available.)

I would think it would be simple but I can’t seem to get anything to work.

I would think that I should be able to have
var plz_validate_these : Array[String] = ["continent","country","city"]
…and then every time I set a value, it iterates through these property names (somehow) to do the validation. Maybe by using get_property_list() and then ignoring any that aren’t in the plz_validate_these array, and then calling _validate_property on it?

Or perhaps by using a getter / setter that somehow calls _validate_resource?

None of the things I have suggested have worked, but it may be because I don’t know about some simple thing, and so…I ask.

Any help would be welcome. (Edited slightly for grammatical clarity.)

…Is it possible that someone here knows what signal or function is used by the engine in the inspector when you collapse / expand a resource?

If I knew that, I bet I could connect it to each relevant variable’s setter function, and then it would work.