What's the point of plugins?

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

I wanted to create my own “unit” object based on KinematicBody2D, and then use it to make other objects that will inherit from the “unit”.
enter image description here
BUT, when I add a “unit” node to the scene, it already contains a script.
enter image description here
What’s the point of plugins then?
Doesn’t that violate the whole concept?
There is a “Node”, “Node2d” is inherited from it, “KinematicBody2D” is inherited from “Node2d”. So why does the created plugin lose the meaning of inheriting one node from another?

:bust_in_silhouette: Reply From: Thomas Karcher

It doesn’t violate the concept, and you can still inherit from the custom node script instead of changing it directly or replacing it: Just right-click on the newly added Unit and select “extend script”. The newly created script will start with something like

extends "res://Unit.gd"

and you will be able to use all functions of Unit.gd plus whatever you add in your extension.

Hmm, a little confusing. The main thing is that it works.
Okay, thanks a lot, tovarishch!

ateff | 2020-12-17 03:13

One more question.
I want to make several child plugins on the basis of my “unit” plugin, for example “player” and “enemy”. How do I add child classes to the hierarchy so that they appear as inherited from the “unit” class?
enter image description here

Of course, I can leave them in the “kinematicbody2d” branch, but I would like it to be beautiful

func _enter_tree():

ateff | 2020-12-17 04:37

I never tried it, but shouldn’t it be enough to assign “Unit” as base node, like so?

func _enter_tree():

Thomas Karcher | 2020-12-17 14:32

Alas, it doesn’t work. I tried to prescribe different options, but nothing helps((

ateff | 2020-12-17 16:33

Ok, I played around a bit and finally got it to work with the following approach:

Do not use add_custom_type, but register your custom scripts as classes instead, with

class_name Unit, "unit_icon.png"


extends Unit
class_name Player, "player_icon.png"

There’re some other disadvantages with this approach (described in Make class_name act the same as add_custom_type but with typed name · Issue #1876 · godotengine/godot-proposals · GitHub), but at least the hierarchical display in the node selection works as expected.

The good news is: The developers are well aware of the mess they created with the two different approaches, and @willnationsdev is already working on a redesign for 4.0: Complete, consolidate, and optimize user-defined types (Script classes/Custom types) · Issue #22 · godotengine/godot-proposals · GitHub

Thomas Karcher | 2020-12-17 19:17

Thank you very much! I will try!

ateff | 2020-12-18 04:17