0 votes

Is it possible to create a new inherited scene from GDScript?
If so, how?

Godot version 3.4.2
in Engine by (78 points)

2 Answers

0 votes

Inherited scene is a design-time concept used in editor.
In code, you just (pre)load a scene from file, instance and then add it somewhere to the tree.

by (1,596 points)

Thank You for Your answer
Unfortunately in my game I have to make a lot of objects which inherits from common one. Its tedious to make them by hand. I guess i invented algorithm to do it in editor plugin but the problem is how in Godot we create inherited scenes. Unfortunately acording to this reddit post

it's imposible to do from code. I hoped You know something they don't.
Best Regards

Do you want to just rewrite/extend editor, or you have a final application?
Can you be more specific about your use-case?

Without that it sounds like XY-problem.

I'm trying to make tool (pun not intended) wchich help me adding new objects in the editor based on asset hierarchy I have.
I make game with a lot of cars. I have basic template from which every car type inherits.
Then I have specific car that inherits its base type.
All I want to do, is to maximally automate the process of adding new car and corresponding resources. It make process faster and more mistakeproof.
Now beacuse i cant make whole process automatic (inheritance must be done from editor, and i dont know C++ to make engine extention), I'm trying to make resources from code and add them to handmade car scenes.
Best Regards

Well, if you want to automate creation of derived objects, why do you need it in editor?

I still don't understand your workflow: surprisingly, I also have a vehicle-themed game with cars, tanks etc. Each vehicle is inherited from a base scene, while customization is defined by exported (and thus editable in inspector) properties and implemented at runtime in a code: like load parameters, specific meshes and materials for parts, etc.

it is very probable that my approach is messy and convoluted. I believe my project structure is a mess too. My backround is artistic and I'm too old to learn programming fast (if its possible by first place). Anyway i'll try explain what I had in mind.

My game is 'simple' 2D runner. I have to add about 1000 vehicles of 200 types. Each vehicle must be unique beacuse only one instance can be in game scene at once. I've learned inheritance from KidsCanCode and tried to apply his approach.
I have base car scene. Inside of it I put vehicles base Nodes( Logic, BehaviorTrees,etc.)
Then I have default car type. It inherits from default template. Here I Change collider shape. From cartype default specific cars inherits. They vary by animated_sprite frames resource. So every car in game is different object (Maybe here lies the problem?). I thought it's possible to automate process of creating animatedSprites in editor and connect them to corresponding scenes.

my goal is to automate as much as I can. E.g. I have store module based on Nodes which is created pure from code and updates automaticly every time if I change list of player cars and reload editor. In this approach only I care is to name player car properly on global list. It elimanated a lot of mistakes I had made without the system and saves me a lot of time.

Now making new car type with testing takes me about half an hour. Multiply it by 200 and You'll understand why I want to automate as much as possible, especially I real struggle in real game logic. So if I could have system which could make new inherited scenes and reseources based on assets I have I would more than happy. Less time I spend in editor and tweak exported variables from there is better for me.

Still I keep going and some day I will learn C++
Best Regards

What exactly do you mean by "automate process of creating animatedSprites"?
Why do you ever need animated sprites? To me - car is a physics and mechanical skeleton/hierarchy of parts. If you have such a varieties of types, wouldn't it better to rely on physics engine like with bodies and joints? Even parametrized AnimationPlayer/ Tween suits better for this.

I believe my project structure is a mess too.

So it's better to sort it out early, than put efforts in wrong approach.

Still I keep going and some day I will learn C++

Don't underestimate complexities and overestimate benefits of this.
I'd recommend to learn general game programming patterns and techniques first.
GDScript will suffice for a this task.

Thank You for Your answers and advices Sir .

When I'm trying to explain how my game works I've realised how surprisingly complex it is.
And unfortunately must be.

My game is isometric 2D with in theory simple mechanics. Vehicle is class derived from Rigigbody2D. All physics is done by Godot Engine. AnimatedSprite is used only as visual representation which position is calculated by linear algebra transformations.

So de facto in the game, vehicle is represented by Rididbody2D's collider but the Player sees visual representation in isometry only.

Maybe my approach to make every car as separate object was a bad idea but It helps me manage them in game.

Anyway. My attemp to automate process of creating AnimatedSprites based on assets finished with success. My plugin creates AnimatedSprites ( and even simple script extending CarTemplate which changes car mass) saves them in target location (e.g. "res://Src/Cars/Resources/SpriteFrames/") and then attaches them to desired Vehicles scenes.

If making inherited scenes would be possible from code, process of creating vehicles that way would be fully automatic and I would be perfectly happy. But besides of that, it's big time saver whatsoever.

Thank You again for Your time.
Good Luck

Aside from technical details (still unknown to me), there's a logical controversy in your approach : you want to automate things - what's normally done in code, and in the same time you need to do this in Editor, which is intended for manual composition of scene tree. It could be I'm missing something important in your explanation - but this how it's seen from my side.

But scenes are text files after all. So (I think) it's still possible to assemble scene-file on disk, if you're accepting risks of future incompatibilities and overall wrong structural approach.

Of course the editor is intended to do things manually. I never negate that and I fully appreciate powerful tools it brings. But all I know about computers is that, they are the best at doing repetitive things and i love to exploit that.

Imagine situation like this. You have car store. Every panel in Your store is composition of nodes (Panels, Sprites, Labels, etc. and the like). Suppose You have to add new car to the game. You must remember to add new panel to the store and adjust all its nessesery data. Of course You can do it manually simple by Ctrl+D and clicking and typing to change information on panels. Every time You want to change something in the store, You have to find it in the nodes structure, then click and type. And beacuse there is a lot of steps to do, it's time consuming and there is always a chance You'll make the mistake.

But if You have tool script which is feed by nessesery data, You can use it to update the store for You, whenever You add new car to the game or change something in car data. If You have such mechanism all You care is to update your base data file.

And this is the Idea I have used in my game for creating repetitive nodes in the editor.

When I made that mechanism I realised I could automate process for creating nessesery resources, e.g. SpritesFrames which I have a lot in my game. I made working editor plugin which makes nessesery resources based assets stored in the project, add attaches them to corresponding scenes and saves them to the disk.

But I dreamed about situation in which only thing I must do is to put the name to plugin and decide where to write it. Not only for resources ( which works) but for creating inherited scenes (which is currently impossible).

And thats it.
Best Regards

0 votes

Beacuse creating new inherited scenes from code is currently impossible
I made proposal to add feauture to Godot engine and it has been accepted.


I hope They add it soon.

by (78 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.