• 2D
  • Export array of enums through _get_property_list() function

Hello, everyone! I'm trying to export Array of enums to editor UI. This can be achieved by below code example:

enum tT {one, two, three};
export(Array, tT) var test;`

However, I can't understand how to replicate the same property export via _get_property_list() function. I tried below but it doesn't work propely (this way it works only if type = TYPE_STRING):

`func _get_property_list():
	var properties = []

	properties.append({
		name = "targetsType",
		hint = PROPERTY_HINT_ENUM,
		hint_string = "one,two,three",
		type = TYPE_ARRAY
	})

	return properties

I also tried to setup my own setter function for test var like below but it doesn't work correctly either:

func setTest(value):
	value = tT;
	test= value;

Can you please assist as I failed to find any example in documentation.

This is probably a silly question, but is this running in a tool script?

I'm not clear on what you're trying to accomplish with this. Are you just trying to constrain the values in the array to the enum, while the game is running? Do you want to throw an error at runtime if a bad assignment is made? I doubt there's an easy way to spot a bad assignment while you're editing.

I don't think you can make a typed Array in gdscript, so it's going to come down to checking every element, every time the array is modified. I suspect that's what the editor is doing when you add elements.