• Godot Help
  • How to automatically set a script as Singleton / Autoload in GDExtension?

I'm following this documentation on GDExtension, Is there is a way to automatically set a script as Singleton (Autoload) without having to manually set it in the editor GUI?

The aim is that if you have the necessary GDExtension files (e.g. gdexample.h, gdexample.cpp, etc) they would automatically be set as an autoload without having to make any changes within the editor? i.e. simply open up the game engine and everything is ready to go

why is this needed?

writing this to avoid xy problem, I have a universal_sub_viewport.tscn scene with @tool mode as such:

Editor Screenshot

and this creates a singleton within the editor every time I start it up, I'm trying to replicate this in GDExtension without having to go through the hassle of setting up anything within the editor GUI

  • xyz replied to this.

    MRM You'll need to make an editor plugin. EditorPlugin class has the add_autoload_singleton() method. You can call it in your plugin's initialization code.

    Btw. are you sure you actually need an autoload?

    • MRM replied to this.

      xyz is there a way to add an editor plugin via GDExtension without using editor GUI ?

      and yes I'm 100% sure I need an autoload

      • xyz replied to this.

        MRM is there a way to add an editor plugin via GDExtension without using editor GUI ?

        I don't think there is but you can wrap your extension into a plugin, so that the only needed setup is the plugin setup. It boils down to simply placing the files, which you'd need to do with the extension anyway.

        MRM and yes I'm 100% sure I need an autoload

        Can you describe exactly what you need it for?