How to define behavior for disabled autoload

Godot Version

4.6.2 stable mono Nixpkgs

Question

Hi! I’m writing a plugin that has a devtool autoload, and would like to branch in script based on whether it’s enabled or not. At the moment, when disabled, I’m getting the following error: Parser Error: Identifier “DiscoDevtools” not declared in the current scope, and as such, can’t branch off anything if the file doesn’t compile.

Is there some form of pre-processor for the parser? Is this doable in some way?

Yes.

Let’s say you have a function in DiscoDevTools named call_function(). You normally call it like this:

DiscoDevtools.call_function()

You would replace that code with this code:

if get_tree().root.has_node("DiscoDevtools"):
	var disco_dev_tools: Variant = get_tree().root.get_node("DiscoDevtools")
	disco_dev_tools.call_function()
2 Likes

Ok so it appears this only reflects whether the autoload is in the tree or not. is there any way to query the status of its “Enable” toggle?

If you need to make that check, the problem is not with how this code is working, but the script - presumably plugin.gd - which is referenced in your plugin.cfg file and how it is loading and unloading the Autoload. If it’s not enabled, it shouldn’t be in the tree. What’s your plugin.gd script look like?

The problem is that I would like the autoload to be enrolled, but I want to query the “Enabled” boolean in the GUI menu, as en end user might like to test the game without tooling enabled, but re-enable it later, without having to un-enroll and re-enroll the DiscoDevtools autoload itself.

Godot has some known limitations when it comes to Plugins. One is that they cannot have dependencies. You gotta work around that. I work around it by putting mine on GitHub. If you really want to separate these two things out, I’d make two folders in the addons folder and two plugin scripts.

1 Like