Can I subclass a Scene class?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CarlF

Note: I also asked this question over at the Godot Forums.

I created a scene for my (2D) game which is a subclass of Sprite. Essentially it’s Sprite, with a script added that makes it draggable during play, and emits a signal when it’s being dragged (which is used to update a label that shows range to a stationary object on the map). Another object, basically a graphical menu, allows the player to create an instance of this subclass of Sprite, which can then be dragged to a selected location.

Now, the game should have multiple objects with similar behavior (draggable, range displayed by that same label) but not identical. I’d like to subclass this one and then change the things that should be different by overriding methods and properties of Barricade (the first class). Is there provision in Godot to subclass a user-created subclass of one of the built-in classes? Obviously I could just copy the class and change the properties/methods, but then if I tweak the script it becomes a nightmare to update all the copies.


:bust_in_silhouette: Reply From: Dooowy.

Here’s a video the might help!
Watch this video Instancing Scenes to a single scene it does what you exactly said and plus its organize-able. Read more about this here.

Thanks for the quick answer, @Dooowy. I know how to instance. As I mentioned, there’s a menu in my game that lets the player create instances of Barricade. What I want is a subclass, not an instance of a class.

CarlF | 2019-07-13 00:05