Adding a custom node to the node list in a way that a script is not attached?

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

The instructions for adding a custom node type to the “Create New Node” dialogue as explained in the “Making Plugins” tutorial is very straight forward. However, this creates a node entry, which when you add it to a scene, has the script for the node already attached. This is clearly intended based on what the tutorial says. Is there a way to create the plugin so that it adds the custom node to the node list in the same way that builtin nodes work? That is, when I add it to a scene, it will just contain extends CustomNode and nothing else from the get go? Even better, if I call get_class() will return CustomNode? In other words, is there a way to make my custom node act as thought it were a builtin node? Of course, I know it will be possible, but can it be done through GDScript? If not, is the process of building the module in C++ (proficient in C++) significantly larger then adding the custom node in its current form?

:bust_in_silhouette: Reply From: Zylann

This is impossible by design currently. It goes down to how scripting works in Godot in the first place, as there is physically no way to inherit C++ classes directly with a script. So what happens is, any script extending an object will be attached to that object, and there can be only one. Even basic classes are just References with a script on them, but from the scripting world you mostly don’t see this due to how it’s integrated.
I would even go further and say, this is not only a Godot thing, I’ve actually never seen engines have this work perfectly, unless when the script language is the same as the engine language.

Yep, extends is a “lie” ^^
So you have to live with it for now, probably change a bit the way of thinking…

There has been a long discussion about this: Better custom EditorPlugin nodes · Issue #6067 · godotengine/godot · GitHub

The reasoning of this seems to be mostly that custom nodes are for a specific usage on a game (for example, to be used by level designers), but defeats the purpose of sharing custom nodes…

If you want to see some work on this, thumbs up (reaction) on the issue mentioned by Zylann in this answer.

eons | 2018-04-07 02:35

:bust_in_silhouette: Reply From: Lab88

I know this post is old, but I was recently wondering the same thing and coudn’t find answers. However, I think I randomly stumbled on a way to do this through GDScript, and wanted to share for others with the same problem :P.
DISCLAIMER, I only have 2 weeks of experience using godot and am not a programmer.

I followed the instructions for adding a custom node type in the “Making Plugins” tutorial, but I also added the line class_name CustomNodeName in my custom node .gd file, right after the extends ... line.

now, when I add in my custom node, it comes with an attached script, but the script icon is greyed out like in this image (in my case, my custom node is called Node25D)
enter image description here

to attach a script on top of this one so your custom node keeps it’s custom propreties and has your new script, I discovered a magic button in the inspector called “Extend Script” in the next image! :stuck_out_tongue:

Bam! this is how I attached a script to a custom node, and every thing seems to work fine!