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

Can't use EditorPlugin.add_autoload_singleton() with a relative path #78049

Closed
sosasees opened this issue Jun 9, 2023 · 0 comments · Fixed by #78109
Closed

Can't use EditorPlugin.add_autoload_singleton() with a relative path #78049

sosasees opened this issue Jun 9, 2023 · 0 comments · Fixed by #78109

Comments

@sosasees
Copy link

sosasees commented Jun 9, 2023

Godot version

4.0.3.stable

System information

Linux/X11

Issue description

when creating addons, i want to use relative paths so that things don't break if i (or another user) decides to rename and/or move the add-on's folder.

using relative paths with add_autoload_singleton() doesn't work because of an error when enabling the add-on.

res://addons/my_plugin/plugin.gd

@tool
extends EditorPlugin


func _enter_tree():
	# this line doesn't work:
	add_autoload_singleton('MyAutoload', 'my_autoload.gd')
	# these lines work:
	#add_autoload_singleton( 'MyAutoload',
	#	'res://addons/my_plugin/my_autoload.gd'
	#)


func _exit_tree():
	remove_autoload_singleton('MyAutoload')

error message window when enabling the add-on

┌─────────────────────────────────────────────────┐
│ Warning!                                  _ □ X │
├─────────────────────────────────────────────────┤
│ Can't add Autoload:                             │
│ res:// is an invalid path. File does not exist. │
│                                                 │
│              [OK]      [Copy Text]              │
└─────────────────────────────────────────────────┘

the add-on does not get disabled because of the error.
the error-free parts of the add-on still get activated, just the autoload doesn't get created.

Steps to reproduce

  1. create a plugin with the subfolder "my_plugin" and script name "plugin.gd"
  2. create an empty script in res://addons/my_plugin/my_autoload.gd
  3. edit res://addons/my_plugin/plugin.gd:
@tool
extends EditorPlugin


func _enter_tree():
	add_autoload_singleton('MyAutoload', 'my_autoload.gd')


func _exit_tree():
	remove_autoload_singleton('MyAutoload')
  1. enable the plugin
  2. see the error message window

Minimal reproduction project

add_autoload_singleton.zip
(13.9 KiByte download, 11.4 KiByte unzipped)

@Calinou Calinou changed the title [addons] can't add_autoload_singleton() with relative path Can't use EditorPlugin.add_autoload_singleton() with a relative path Jun 9, 2023
@YeldhamDev YeldhamDev added this to the 4.1 milestone Jun 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants