[ad_1]
If you happen to make an script like this:
@software
extends CharacterBody2D
class_name Player2D
Then you possibly can add a CharacterBody2D
to your scene, give it an script, and it’s write this:
extends Player2D
And it ought to work. You would possibly want so as to add @software
to it, relying on what you need it to do.
This has pushed me to make my scripts extra reusable. As I usually want to contemplate learn how to lengthen them aside from including an script to them. Some instances which means creating nodes that count on to be positioned as kids of a node of an particular kind. In different circumstances it means having a node work together with their kids, or including customized indicators, or export nodes variables.
If you happen to had been so as to add the customized class by way of en EditoPlugin
with the now discouraged API add_custom_type
as a substitute of utilizing class_name
what you’ll acquire is Godot stopping you from eradicating the script, and avoding a little bit of namespace air pollution. Which for me be too little acquire for the effort, as EditorPlugin
s additionally have to be enabled within the editor.
Nevertheless, I wish to word that should you want customized habits within the editor, you would create an EditorPlugin
that handles your nodes (in your case it may deal with CharacterBody2D
for instance), so the additional logic you want isn’t on a base class. Whereas the EditorPlugin
will not execute in runtime, it may possibly manipulate the scene within the editor, for instance mechanically including different nodes with their very own scripts, which might execute in runtime.
Nevertheless, it appears you need to have the ability to add a Player2D
to the scene and have it seem with out an script… In that case the Player2D
class should not be an script. Which on the time of writing means to both:
This could additionally let you keep away from overload from the GDScript runtime. Which makes it a good suggestion for efficiency important code as soon as different avenues of optimization have been exhausted. Additionally since it’s much less engaging for fast prototyping, the same old recommendation is to design what you need with GDScript after which port it.
[ad_2]