+1 vote

I have a script that I have added as an AutoLoad in project settings in order for the variables established in the script to be global. However, I cannot access the variables in the script unless I assign the script to some scene in my project, is this intended behavior?

When the script is not assigned to anything, but IS set as an AutoLoad, initially I get an error that the referenced script is not established in the scope of whatever other script I'm trying to reference the global variables from. This error goes away when I restart Godot, but then it throws an error when I try to run my project, telling me the referenced global script is a null instance...

Godot version 3.4.2
in Engine by (93 points)

2 Answers

+1 vote
Best answer

There is a known bug in godot 3.2 which loads autoload too slow compared to scenes ready. It happens when total project became large and error happens 30-50 % of times on trying to run the project.
If You can't run project at all, that means You must have done some mistake regarding setting autoload. Is your autoload simple Node ? Can You show pieces of this code ?

by (7,755 points)
selected by

You know what, it's working now. Not sure what I changed, but yeah, it seems like it was just that glitch and changes I've made since the issues started have fixed it, interestingly enough.

This is very frustrating issue, You will repeatedly encounter it every time You work on project over than an hour or just leave Godot open for longer time. Resetting temporarily helps.

+2 votes

I have no answer, only a work-around.

The documentation says a script can be an autoload, and I have used a script as a collection of static functions. The documentation stays silent on what, exactly, is a script as an autoload, what and when variables are evaluated, and what is available to a tool.

The simple work around is to create a new scene with just a node and that attached script. Make the new scene an autoload. Being a scene, it will follow the normal lifecycle and be made ready before any of your written scenes.

by (335 points)

This is great information, an awesome suggestions, thank you!

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.