Topic was automatically imported from the old Question2Answer platform.
Asked By
nwgdusr999
I’m having a hard time understanding why I’m getting an “Invalid call. Nonexistant function ‘xxx’ in base ‘Nil’” error… So I have an autoloading object ‘Global’;
Global (autoload in the project settings):
extends Object
class_name Global
static func xxx(var x):
return '1':
Method call:
Global.xxx(0); // "Invalid call. Nonexistant function 'xxx' in base 'Nil'"
If I try to call the function, I get an error which seems to imply that ‘Global’ is null/Nil… Well yeah, but since the function is static, isn’t it the point? Shouldn’t it work nonetheless?
an autoload singleton is actually just that… a singleton. there is one instance of this class when you run the game/app. the name given in the autoload menu is how you access that class. no need for a static function and you dont even need to give it a “class_name”
Thanks for your help! Re-read and reread and after much thinking, figured out why it wasn’t working in my case… Object!! Singleton must be a Node…!
nwgdusr999 | 2019-11-30 23:52
AHH! wish I could have caught that and been more specific. Thanks for sharing!
After much confusion about my ‘Global’ singleton throwing compiling errors and crap, I just realized my mistake. It was type Object, which basically breaks everything… It really needs to be Node to be working as a Singleton…! As an Object, it is always ‘null’ globally; likely because it can’t be added to the root node. So, must be node!
I have just spent an hour with the exact same problem and exact same solution… I figured it out as well, I really think this should be noted in the docs, I will try adding it.
Adam Volný | 2019-12-07 16:51
If you want to maker a helper class. then use class_name or add singlton. You dont need use them both. And class_name with extends Object is working