Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_init function of autoload executes when opening editor #19935

Closed
sdfgeoff opened this issue Jul 3, 2018 · 7 comments
Closed

_init function of autoload executes when opening editor #19935

sdfgeoff opened this issue Jul 3, 2018 · 7 comments

Comments

@sdfgeoff
Copy link
Contributor

sdfgeoff commented Jul 3, 2018

Godot version:
Current Master

OS/device including version:
Arch Linux, updated recently™

Issue description:
The _init function runs in singleton scripts are running the editor opens. This isn't really a problem as for singletons, _init is effectively _ready, but I do find it a little strange.

Minimal reproduction project:
singletontest.zip
If you open Godot from a terminal, you will see it print "WHY DID I RUN". It does not appear inside godots UI as it runs before the godot editor is open.

@vnen
Copy link
Member

vnen commented Jul 3, 2018

They are instanced in editor and added to script globals, so they can be easily referenced in scripts. If this is really an issue I can change the system to avoid it.

@sdfgeoff
Copy link
Contributor Author

sdfgeoff commented Jul 4, 2018

So it's just for the purposes of auto-complete? Hmm. I would suggest removing it, if only to prevent potential issues later.

There are already some issues that may be related to this, but I haven't been able to pin down if this is the exact cause:

  • if you use preload() on an imported resource (eg an escn, dae, image, etc) from one of your autoloads, and if the resource hasn't been imported when the singleton runs (eg you delete the .import folder then open godot), then you get errors in the console about how it is failing to load the resources.
  • On some PC's in some situations, having a gdnative library preloaded from a singleton causes the editor to crash when importing scenes.

@sdfgeoff sdfgeoff changed the title _init function of autoloads when opening editor _init function of autoload executes when opening editor Jul 4, 2018
@vnen vnen added this to the 3.1 milestone Jul 4, 2018
@vnen vnen self-assigned this Jul 4, 2018
@vnen
Copy link
Member

vnen commented Jul 4, 2018

So it's just for the purposes of auto-complete?

And static checks. But I guess it only needs to be compiled, not instanced. I'll disable the instancing for non-tool scripts then.

@vnen
Copy link
Member

vnen commented Jul 4, 2018

BTW, if you are preloading things in the script, they will be loaded if the script is loaded, even if it's not instanced. So I don't think it's possible to avoid the issues, in this case you should not use preload() but load() instead.

@akien-mga
Copy link
Member

And static checks. But I guess it only needs to be compiled, not instanced. I'll disable the instancing for non-tool scripts then.

Wasn't the idea also that autoloads should be available in the editor for the use of tool scripts?

@vnen
Copy link
Member

vnen commented Jul 4, 2018

Wasn't the idea also that autoloads should be available in the editor for the use of tool scripts?

Yes, but it only works properly if the autoload is also a tool script.

@darco89
Copy link

darco89 commented Dec 1, 2024

Hello everyone (who's still kicking it after 6 years),
I understand that this is closed, but I'm just looking for confirmation.

I have a dbcontroller class (SQLite) that is used by a few EditorScripts of my own.
Whenever I open this project in Godot, the SQL connection is set and opened (I close it too). I didnt really want this to happen. I can close it, but the connection was made, regardless.

Is this controller's _init function running when I open the editor, just because it is referenced in an EditorScript?
If so, is there a way to make sure it won't run, until I execute the EditorScript?

Thanks for the clarification in advance, best regards

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants