+6 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 (107 points)

1 Answer

+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: https://github.com/godotengine/godot/issues/6067

by (28,744 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.

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 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 webmaster@godotengine.org with your username.