The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

+7 votes

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?

in Engine by (113 points)

2 Answers

+6 votes
Best answer

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:

by (29,360 points)
selected by

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.

+1 vote

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! :P

enter image description here

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

by (16 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.