Is a Node an object instance of the script it is attached to, or simply a separate object?

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

i’m wondering if when you extend from super-classes, the node the script is attached to becomes an instance of the subclass the script represents. or maybe it’s just some separate object that is paired with the script in some way?

Not entirely sure but your question is a really good topic to open up for discussion so if you haven’t already also include it in the Godot forums.

My money is on your first suspicion as you can extend in reverse of the node tree and lose all of the current class’s implantations yet never future version of that same node.

if base node is Control

extend Node 
# works
# no Control members like rect_position
# instance becomes Node in sceneTree

extend Button #fails

Understand your confusion like shouldn’t a node be whatever a script tells it to be?

Honestly it’s best to avoid the whole Node paradigm and use Class Reference instead only extending a node when you need Node specific behavior or visual representations

Wakatta | 2021-11-30 12:06

:bust_in_silhouette: Reply From: siska

I have the same question.

I always assumed a script ‘augments/customizes’ the node it’s attached to, but that they are basically the same thing. However, when you mark a script as ‘autoload’ a new node is created in the senetree (you can see this in the ‘remote tree’ when you run the scene). This new node has the same type as the script, but it is -not- the node the script is attached to …

I wondered if you have more information on this now ?