OPEN Confused about extending

What does ‘change type,’ and ‘extend script’ do?

When I tried them, they attached the actual class script onto them, which isn’t the purpose because what if you were trying to add features upon them?

And does that mean custom classes don’t function as a Godot node type?
When I tried instance a player class node into a scene, it had the class script attached.

If custom classes don’t function like that, why don’t they create a new script, extend it from the class, and boom?

I’ll close this once I find a reply that solves my question.

Scripts are not Godot nodes, they are very close to being the same, with a few meta-drawbacks. Like get_class will never return a class_name.

It’s a sort of shortcut for that. Extending from non-class_named scripts is easier than typing extends "res://example.gd" but you could also drag in the filepath from the filesystem; just another shortcut.

Change Type can change the underlying node type, not just the script attached to the node. Though it’s best used on nodes that do not have a script attached.

When you create a Node3D, it doesn’t require a script saying “Extends Node3D”
But, when I try to create a custom class and remove its script, it returns to Node3D.

Also when using “change the type” or using the “extend script” thing, how am I supposed to use it?
For me it’s a copy of the class script I made that the node should be extending but in the code it has the whole “class_name extending ,” which is definitely not extending my class. So I usually create my own script saying “extends ”. And that works.
However from what these features do, it leads me to believe that, that is the incorrect method.

Sorry if this is really long and you still don’t understand.

Only if you are creating a custom class in GDExtensions. Scripts, when attached are the custom class, they do require the underlying node follows the same inheritance as the script.


These are two different operations. Change Type only affects the underlying node type, which may affect the script by simply erroring in-game if the new Node type inherits differently from the script’s type. Generally if the node has a script, it’s a bad idea to change it’s type.

Extending a script should create a new script with

extends "res://your_script_file.gd"
# or if a class_name was declared
extends YourClass

The extended script inherits all of the previous script’s members and methods, similar to inheriting a node’s members and methods. You may have to call super() to access overriden functions like _ready() if the function was present on the inherited base script.

If your version of Godot instead only adds class_name YourClass to the extended script, that is a bug, and you should update to the latest stable version.


What are you trying to do specifically? What problem is to be solved by extending? Maybe we can figure out the correct method for your situation.

1 Like

Oh yeah, sorry.

I am trying to do is add a script with only “extends ”
But from what you said, using the extend script feature creates a script with only
Meaning it already does this:

extends Custom_Class

And nothing else
That’s not how it worked in my testing, but I’ll try again.
For me (I might be mixing it up with the change class thing) it is either instanced, duplicated, or attached (I don’t remember) the entire class script, including all the methods, but they were exposed.

If this isn’t true, you don’t need to reply cuz I’m about to test it myself.

Since it seems like it copied the class script. I thought maybe just extending the class (nothing else) was bad practice.
So instead of attaching the class script, its just

extends Custom_Class

If I’m confusing you I’m sorry!
Ill figure it out eventually on my own if you don’t have the energy to reply.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.