Extend Control or Node?

Godot Version

v4.6.2.stable.official [71f334935]

Question

Hi Everyone,

If my project and scenes only use control nodes and my main script for each scene also extends control, should any global scripts I create and reference from scene scripts also extend control?

Godot’s default when creating a new script not attached to an object is to extend node.

Probably a simple thing I’ve just overlooked in the documentation, but I can’t find a definitive answer. I can’t really see any difference in function, so it’s really just a matter of semantics, probably.

Kindly,

Ryn

1 Like

No, that’s not required.
Extending Node in your autoloads is perfectly fine.

1 Like

I think “extends Node” is just a placeholder for the autoload. It doesn’t affect any of your control nodes. But that’s my guess

It’s not a placeholder. It’s the actual type of your autoload Node.
The autoload is a Scene instantiated in the SceneTree, so it can be any Node-derived type, like Control, AudioStreamPlayer, etc. In most cases, making it just a Node type is enough though, so if you don’t need any specific behavior, you don’t need to change it to anything else.

2 Likes

Sorry. I’m new to Godot, I was just going off of what I knew

Hi

Thanks,

I’ll leave them as Node as that is the default and I see no difference either way. In the example in the documentation it says to make sure it extends Node, though I’m not sure if that is for just that demo project or as a rule.

Thanks for the help all.

Kindly

Ryn

All nodes in Godot extend node, including Control nodes, Node2Ds, CharacterBody2D, all of these extend node.

I recommend reading up on Object Oriented Programming to understand how inheritance works. That will help you understand why this is the case, and how you can make use of this in your games.

1 Like

Thanks,

I understand OOP, been programming for many years, was just curious when creating an autoload and whether keeping it at the same level / scope in the OOP tree was preferred in Godot.

I appreciate your advice I’ll read up some more on Godot’s implementation of OOP.

Kindly

Ryn

1 Like

If you look at any node in the inspector, you’ll see it’s inheritance laid out in all cases.

From top to bottom, you have Area2D in this example, which inherits CollisionObject2D, which in turn inherits Node2D, which in turn inherits CanvasItem, which in turn inherits Node.

PS: No need to sign your posts. We can see your profile name.

That’s true for objects in your scene tree but how do you see the inheritance for a script used as an auto load not attached to an object?

Autoloads are still just nodes attached to the scene tree.