Extremely annoying random(and not justified?) error about an autoload class

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

Parser Error: The identifier “GLOBALS” isn’t declared in the current scope.

That’s the annoying error that sometimes appears, GLOBALS is an autoload class with some global variables, the problem is that error decides to appear sometimes when everything works, in fact if i just run again the game again it works without any error.

Sometimes it appears rarely, recently is appearing more often so i can’t stand it anymore.

Anyone know what’s happening?

Should i eventually open an issue?

EDIT:
i forgot to say that the error appears just when the window of the game shows, but when the error appears the window is with borders and something like 1024x640, but i want a 720p borderless window(and that’s how the window is created when the error doesn’t appear), so i think that something is wrong already before the appearance of the error.

Can you provide an example project? (That’s a requirement for opening an issue as well)

njamster | 2020-04-03 21:15

Something noticable in the output window?

Maybe the error happens in the ready handler of the globals script.

Maybe there’s a file access which causes an error due to a locked file or access rights errors (i.e. some people try to write to files in the res:// directory).

wombatstampede | 2020-04-04 14:23

I thought it would be hard to make an example project because:
1)i don’t really know the cause
2)the error appears randomly

but making an example project is probably literally impossible because:
3)i was trying to make an example starting from a scene that was giving me the error, i made a copy without any changes but guess what the copy doesn’t give me the error while the original around 50% of the times gives me the error.
4)i made another copy without any changes from the original and this one gives me the error but again the first copy doesn’t give me the error.

I opened the .tscn files with a text editor, copy1 and 2 are exactly the same while the original scene has a different ext_resources order.

I tried with another scene that gave me error and i was able to make a minimal copy scene that sometimes (1 over 8 times more or less) gives me error, but if i make a new project for the error and copy the scenes i don’t get the error.

The window is the default 1024x600 border window, it’s like if godot doesn’t read the settings when the error appears, and maybe that’s exactly the reason, after all the autoload class are part of the settings right? If godot doesn’t make GLOBALS a singleton the other classes can’t reach it.

If you really want to try(but it’s probably just a waste of time) the minimal scene i made is like this, you need 2 scenes with those gdscript lines:

-GLOBALS
extends Node
var PLAYER

-NODE
extends Spatial
var owner=GLOBALS.PLAYER

in the project settings change the windows settings and put GLOBALS in the autoload and then run the NODE scene many times until the error appears(but it probably won’t appear).

At this point my bet is either on something that makes godot skip the project settings(that would explain the window and the error but not why this happens with some scenes and others not) or on something that messes with the initialization/call/whatever order(that would explain the error and maybe why it happens on some scenes and not others and why it doesn’t happen in simple projects, but it wouldn’t explain the window settings) or maybe both.

2plus2makes5 | 2020-04-04 17:43

var owner=GLOBALS.PLAYER

That should throw an error: “The member ‘owner’ already exists in a parent class”.

I created a fresh project after your instructions (but changed the variable-name to owners, so that I’m able to run it) and run it 50 times: no problems on my end.

njamster | 2020-04-04 23:07

As expected you got no errors, maybe it’s some editor or project setting, but it definitively needs some a larger project to show the error.

About “owner”, in order to make things more clear for everyone i translated all the word to English from my language, so yeah you are right “owner” should give an error if used that way, i didn’t think about it when i wrote this question.

There was no need for 50 tries! I really really really thank you for trying to help me so hard! :smiley:

2plus2makes5 | 2020-04-05 15:14

:bust_in_silhouette: Reply From: Poobslag

This happens to me as well; about 25% of the time in my project I get a “SomeAutoloadScene is not declared” error if I launch an individual scene. It seems to be happening more recently, although the autoload singleton and class causing the error haven’t been changed in several months.

The error happens more and more as my project grows, and I add more singletons. It always happens in the same place (a setter referencing a singleton) and always with the same singleton. If I launch the same scene a second time, the error doesn’t happen. It just seems like a coin flip whether it happens or not. It does not happen when I launch the full game; only when I choose a scene to launch. I am running windows.

I’m unsure what an example project would look like, given that a prerequisite appears to be having a large project with many autoload singletons, and perhaps a project complex enough to incite a race condition.

:bust_in_silhouette: Reply From: Inces

I was just about to create new question and name it exactly as yours…
So I add myself to this question, this is top frustrating Godots error.
What I noticed, is that propability for this error is proportional to size of project and runtime of Godot , even if You just left it on, not working on it. After an hour it will annoy You every other try to run project, after 3 hours it will cast error 3 or 4 times before You can run project. Exiting editor and opening again clears the issue… for another hour. I really hope it will be past in Godot 4.0