Topic was automatically imported from the old Question2Answer platform.
Asked By
scrubswithnosleeves
Hey All,
I have some Autoloaded Singletons added from an EditorPlugin node as well as one that I set up in the editor as a test.
In the ready function of some node, I have this:
if Engine.has_singleton("NewScript"):
print('yup')
else:
print("nope")
NewScript is definitely there under Project Settings > Autoload. Am I confused as to how this function works? If so, how would I go about checking if a singleton exists?
Those function operate on built-in engine singletons like Engine or Input, not on user’s autoloads.
print(Engine.has_singleton("Engine")) # prints 'True'
For accessing autoloads one can use the name from the first column of autoload settings, e.g.
NameFromFirstColumn.myFunction()
It only works if “Singleton” column is checked (it is by default).
Since autoloads are direct children of root their existence can be checked like this:
print( $"/root".has_node("NameFromFirstColumn") )
Naming of “Singleton” column in autoload settings is unfortunate. A better name would be “Global” as it adds a global reference. It wouldn’t confuse people as much.
I’ve opened an issue on github for this: