![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | SethielCZ |
Hi all,
I’m a programmer of about ten years now and I’m just starting out with Godot Engine. First I was really surprised (in a nice way) by the tree structure - it looked very clean and systematic. But the more I learn about inheritance (which is something that feels absolutely necessary to me), the more confused I am about the role of nodes vs scripts in an inheritance tree.
Why are a node and the script that is attached to it different things? Why isn’t extending a functionality of a node with some code inheritance itself?
It really seems like when I want to create an abstract scene (entity in the game world), then extend that in several ways depending on the role of that entity - I should be creating two parallel inheritance trees, one for the scenes and one for the scripts, both connected via the “script attached” relation. I want to progressively extend both what are the entities composed of and how that parts that they consist of behave.
I’m also very confused about the fact that scripts inherit from nodes. That I can write a script that extends a script, but also a script that extends e.g. KinematicBody. Which makes no sense to me since the script is not a node and does not belong to the scene tree. At least if I understand it half right.
I went through some tutorials, but I’m yet to find one that actually focuses on making clear how all the nodes, scripts and scenes relate to each other when inheritance of scenes and inheritance of scripts is used.
If there’s anything that explain this side of Godot design, I’d be very grateful for any links to it or advice in this matter.
Thanks.
=====================================================================
Edit: Looking back at this chaotic question, I doubt anyone would be able to give any meaningful answer. But I did manage to formulate one much more specific question:
When I create a scene (Character.tscn) and add some variables and functions to it via attached script (Character.gd), I’m not actually adding those variables and functions to the scene in a way that would allow me to use them through inheritance, right? Meaning, when I then create an inherited scene (PlayerCharacter.tscn), I can see it has attached the same script (Character.gd) automatically. But when I want to write some code that uses variables and functions that Character.gd added, it really looks like I need to detach the script Character.gd from PlayerCharacter.tscn main node (because I cannot attach two scripts to a node) and create a new script, PlayerCharacter.gd, that extends Character.gd (because whatever I added to Character.tscn with my script Character.gd is not actually inherited with inheriting Character.tscn itself). So I’m actually doing two parallel inheritance trees that are connected at some points. Is that correct? Is that the way the inheritance must be used? Because what I (and basically everyone imo) needs when e.g. adding properties to a node (scene) is extend the functionality of that scene, and it really seems like this extended functionality is not inherited unless I do this complicated mess of relations.