How to create an enum selector in a plugin

Godot Version

Godot 4.2.stable

Question

If I export a variable with an enum type, when I assign the variable in the inspector, the inspector automatically provides a drop-down menu with the possible enum values to choose from.

Is there a way to basically create this kind of drop-down menu for a plugin?

End goal:
I have a type of custom resource in my game and editing resources one by one in the inspector takes too long, so I want to make a plugin to edit resources in bulk. However my custom resources makes use of a lot of enum variables and I’d like to be able to link them up to the interface like the inspector does automatically.

Hi! Like so?

enum ChooseMe {Me, NoMe, NonoMe}
@export var chosen : ChooseMe

This defines an enum, then allows you to use the Godot Editor to present a dropdown menu.

This allows me to choose a value from the inspector menu. I’m basically trying to recreate this behavior on a custom plugin screen. I think it will involve recreating this selection menu using control nodes, but I’m not sure how to do that.

Ah, sorry, I misunderstood.
The Editor does this via cpp I think. But for your needs you could use an OptionButton and set its items to your enum values.

Ah thanks! I think that’s what I was looking for!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.