I can do Sprite.new(), but I can't do CustomNode.new()

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By gothrond

I created a CustomNode as a plugin, and when I add it to the scene tree, there it is, for me to select. But what I really want to do is add it to my scene tree from code. So, when I do CustomNode.new() I get an error, “The identifier “CustomNode” isn’t declared in the current scope.” I can do Sprite.new() etc, but it won’t let me do my CustomNode.new()

:bust_in_silhouette: Reply From: Kronos328

Could you provide the code of the CustomNode, please? Maybe it’s something there.

Also, did you activate the plugin on the project settings? You can check it on Project > Project Settings > Plugins, and see if your plugin appears there and is activated.

:bust_in_silhouette: Reply From: gothrond

Thank you for responding. Yes, I did activate the plugin and it appears. But I actually found something that seemed to fix it. All I had to do was put this line in my custom_node.gd file. The line is: class_name CustomNode. This wasn’t in the guides and tutorials I was using, I saw class_name class for defining classes and thought it might work for this custom node as well and it worked!

Now the class is recognized it when I put in the code: CustomNode.new()

Maybe this solution is obvious for some people, but not for me.

Thank you!