• Godot HelpProgramming
  • Get an Inherited Scenes script to extend the base scene's script instead of copying it.

Hey all, I have a set of equipment I want to make for my game and realized that some inheritance would go a long way to making the system more maintainable. I've run into a bit of an issue, though. I have made my base scene, which also has a script with some properties in it and I want to put a method stub in there. Easy enough. The issue comes when I make a new inherited scene based off of my base scene. The scene stuff is fine, but Godot just copies over the script connection instead of creating a new script that extends the base scene's script which I feel would be much better inheritance. I found this older reddit post of someone who said they thought that was already a thing, and to be honest I thought it was, too. Is there some way to get Godot to do this? Is it a planned feature?

Example: Base.tscn Base_Script.gd

Potential content of Base_Script.gd

export(Color) var color
enum Equipment { SHOVEL, SWORD }
export(Equipment) var type

func _ready():
	// Stuff here maybe

func stub_method():
	// Logic to be overloaded (if that's possible?)

Shovel.tscn (the inherited scene, which works as expected) No Shovel.gd is made

Connected to Shovel.tscn would just be the Base_Script.gd which doesn't allow for proper script inheritance at all. I know I could just make my own script, which if that's what I gotta do I'll do it, but it just feels a little lack luster. Wanted to make sure I wasn't missing something first.

2 months later

Hi,

I think it is just expected behaviour from godot side. When you create new inherited scene it just have all the base scene setup done by default because maybe you don't need to expand scripts at all (just update some nodes/current scripts properities etc. that may be also the case).

You can easily create inherited script by right click on node with script and select extend script (it will create inherited script and assign it to node), that seems to be pretty easy and not too complicated.

I am also working for equipment for my project and my approach is to create scenes only as graphics representation of equipment, but logic is saved in scripts (base script inherits Resource) and I just exported PackedScene to let me select "model" for every new equipment I add. That way for new type of equipment you need to create just new script (not scene) and if you have for instance many different swords you can create them by creating new resource for each (and select different model for every sword you created).

To show hierarchy it is something like: Equipment extends Resource Weapon extends Equipment Sword extends Weapon

Now making many swords is as easy as create new resource->sword for every sword you want.

I hope it may help you.

2 years later