Error when accessing global enum

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ben Humphries

I am storing an enum in as follows:

extends Node

enum TileType {

When I try to access a value in the enum from another file,, I get this error:

 res://scenes/ - Invalid get index 'SOLID' (on base: 'GDScript').

In this file, the enum is declared like this:

const TileType = preload("res://scripts/")

According to other Q/A’s I’ve seen online (see below), this seems to be the way to use a global enum. Am I missing something?


:bust_in_silhouette: Reply From: hilfazer

These days enum values require to be prepended with the name of enum, like this:


Thank you, that worked for me.

I suppose this makes sense as I’m loading in a class with an enum inside it, but it still feels bloated. Is there a way to use the syntax “Enum.Value” in multiple scripts?

Ben Humphries | 2020-06-02 10:14

I don’t think it’s possible. What you can do is not use an enum but a couple of constants:

const EMPTY = 0
const SOLID = 1

As a bonus you won’t be able to accidentally delete these constants. Sadly, enum’s contents can be deleted.

hilfazer | 2020-06-02 11:31

Great idea. Thanks again!

Ben Humphries | 2020-06-02 12:14

:bust_in_silhouette: Reply From: sairam123

Just declare the enums without any names.

Like this:

enum {

then you can access like this

:bust_in_silhouette: Reply From: Pdcl

I run into this behaviour when autoloading a script file that contains an enum. To fix this behaviour i usually assign each enum value an index number, so it would be:

extends Node

enum TileType {
    EMPTY = 0,
    SOLID = 1

If I omit the index number, then I get that error.

:bust_in_silhouette: Reply From: Nenja

Note: I’m using v3.3.2

I had the same issue. For me, the actual problem was preloading - in an autoload script - a script which referenced another autoload script. See the following simplified example of the problem and then the solution afterward.

Autoscripts (in order)


var Tile = preload("res://Tile.tscn") # <-- This caused the error
var tile = Tile.instance()
# do stuff with tile


export(Config.TILE_TYPE) var type = Config.TILE_TYPE.NONE

By removing the preload of Tile.tscn from, the error went away. For me, this is an acceptable solution because I’m realizing in hindsight that instancing Tiles elsewhere is more appropriate.

I also verified that referencing enums in from within works. E.g.

func IsAWall(pTileType) -> bool:
   return pTileType == Config.TILE_TYPE.WALL

If you need to preload - in an autoload script - a scene which references enums in another autoload script, similar to what I was doing in, then you need to preload the autoload script similar to one of the following examples, depending on your use case.

export (preload("res://Game/").TILE_TYPE) var type


const TileTypes = preload("res://Game/").TILE_TYPE

Hope this helps others!