0 votes

Imagine I have a scene Soldier which has Sprite, collision shape and sensory area (area2d with another collision shape)

And I want to create a different soldiers with different abilities that need additional nodes in their scenes. For i.e. mortar soldier needs area2d for detect targets that available for attack and smaller area2d for detect targets that are too close for attack.

I can inherite the new Script from Soldier script but I still need to create the new scene with the same nodes + new nodes of this unit.

Is it possible to use inheritance in scenes to reuse the nodes of parent's scene?

in Engine by (267 points)

2 Answers

+1 vote
Best answer

I suggest you look up the Godot documentation for scenes and inheritance. It should have a lot of the information you're looking for! Here are some pages to get you started:

Inheritance of Scenes, per se, is not available, but you can do a lot with what you already have.

It sounds like you should set up the Soldier scene, then make multiple instances of it. In your Soldier script, create a method to change the type of soldier so you can specify what each instance of the soldier should be. For your mortar soldier, have that method create the two new Area2D nodes then add them as children of the soldier. It should also set up the appropriate signal connections for the new Area2D nodes.

Let me know if this helps!

by (85 points)
selected by
0 votes

In Godot, you instance a saved scene as a node into a new scene to inherit it.

by (191 points)

But will the GDScript that inherited from parent's scene GDScript see all parent's components on the same pathes?

This doesn't allow modification of each soldier individually since they still share all the same resources.

I don't understand :(

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.