"Trying to access non-existent autoload singleton" during editor plugin restart

Godot Version

4.7.stable

Question

I making editor plugin with autoload singleton like this:

func _enable_plugin() → void:
     add_autoload_singleton(“PnCEditorConnector”, “res://addons/quest-editor/editor/pnc_editor_connector.gd”

And i want to access this autoload in _ready of my node:

func _ready() → void:
    PnCEditorConnector.reactiveProject.get_ids_list(type)

But whene I restart plugin (disable/enable) i get error:

Trying to access non-existent autoload singleton “PnCEditorConnector”.

When I restart whole editor there is no error.

After some testing i know that in the same place

   EditorInterface.is_plugin_enabled(‘quest-editor’)

returns true

So there is time window where plugin is enabled but autoload is not initialized yet.

Is there better place to access autoload than _ready
or I have to add timeout:

 await get_tree().create_timer(.1).timeout;

before accessing autolaod?

Couple things:

  1. I strongly recommend you attach that script to a Node and load that as you Autoload instead of a pure script. There are lots of reasons for this.
  2. Your second script is experiencing a race condition. If it is a @tool script and your Autoload is not, that is why. Make your Autoload a @tool script, and the problem will go away.