How would I build a script into a custom node?

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

Let’s say I build a custom button and have a script I’ve written that extends the button class, but includes several additional functions. I’d like to make several instances of this custom button class with their own unique scripts that extend the custom button script. Is there a way to tie the custom button script behind the scenes to the custom button scene? I want to have access to all the custom button script’s features when a new scene is instanced without a script, and have a newly added script automatically extend the custom button script when added. Essentially, I want to build my own node. Can this be done?

:bust_in_silhouette: Reply From: Inces

use this keyword right after extendsline, followed by your chosen name. From this moment on You will be able to see Your class among other nodes in editor, it will also be autocompleted when typing in editor. When You drag it into viewport or create it on run by code with .new(), it will basically be the node You extended it from with all your additional code.
If you modified exported buttons properties in editor and saved it as a scene, these changes will not be remembered by class script. Still You can just add your class script to the modifed button scene and save it again. From this moment on your other custom button classes can inherit from whole scene.

Thank you so much!!!

YangTegap | 2022-06-20 23:29

When I do this and create a new node of the class, it automatically creates the node with the script that I have attached to the base scene and doesn’t automatically let me create a new node extending the new node type. Am I doing something wrong?

YangTegap | 2022-06-21 00:02

When you choose your custom node from node list and add it to the tree, it should look scriptless, script is behind the scenes, and adding new script should automatically extend your custom class. Now You can use classname once more to create subclass, and so on

Inces | 2022-06-21 16:40