Handling enum in a custom resource

Godot Version




I have a custom resource and one of the variables should be a value from pre-defined list. So I thought enum would work. But I’m not sure how (or where) to create this enum so that it can be used everywhere in the project and also in the custom resources.

In the custom resource below, variable type should be something that I can select from a list (ActionType) like an enum. And I can also access to that same enum anywhere else in the project.


extends Resource
class_name Actions

@export var id: int
@export var name: String
@export var type: ActionType


I think you could maybe reference the enum by putting it in an autoload.

Enums and constants are part of the class, not part of a class object like variables. That means you can reference them through the class from anywhere.

class_name Actions
enum ActionType { TYPE1, TYPE2 }

@export var type: ActionType
class_name SomeOtherClass

@export var type: Actions.ActionType = Actions.ActionType.TYPE1
1 Like