Files
godot-website/collections/_release_4_5/entry-scripting-gdscript-abstract-classes-and-methods.md
Adam Scott 5387797774 Godot 4.5 release page
Huge thanks to JohnVeness, AThousandShips, and Meorge for their
great help rewording my broken English.
2025-09-15 16:03:40 -04:00

1.9 KiB
Raw Permalink Blame History

type, section, subsection, rank, importance, anchor, title, blockquote, text, contributors, read_more, image_alt, image_src, image_src_2x, media_position, position
type section subsection rank importance anchor title blockquote text contributors read_more image_alt image_src image_src_2x media_position position
entry scripting gdscript 1 3 abstract-classes-and-methods Abstract classes and methods U Cant Touch This You can now declare GDScript classes to be abstract. Declaring a class abstract means that the class is not meant to be instantiated directly. That means that you can prevent instances of a class, lets say, ``@[Animal](usertype)``, that doesnt have any purpose on its own other than to be extended by "concrete" classes like ``@[Cat](usertype)`` and ``@[Dog](usertype)``. Abstract classes can also have abstract methods. This means that the method must be implemented in any class that extends it. <figure class="file"> <figcaption>animal.gd</figcaption> ```manual @[@abstract](gdscript-annotation) @[class_name](keyword) Animal @[extends](keyword) @[Node](enginetype) @[@abstract](gdscript-annotation) @[func](keyword) @[cry](function)@[() ->](symbol) @[void](basetype) ``` </figure> <figure class="file"> <figcaption>cat.gd</figcaption> ```manual @[class_name](keyword) Cat @[extends](keyword) @[Animal](usertype) @[func](keyword) @[cry](function)@[() ->](symbol) @[void](basetype) @[# Must be implemented, otherwise an error will be thrown.](comment) @[print](function)@[(](symbol)@["Meow!"](string)@[)](symbol) ``` </figure>
name github
Aaron Franke aaronfranke
name github
Danil Alexeev dalexeev
name github
Ryan Brue ryanabx
https://github.com/godotengine/godot/pulls?q=is%3Apr+is%3Amerged+67777+106409+107717 Image of the Add Node window displaying the dimmed out abstract Animal node, and its two extending classes Cat and Dog. /storage/releases/4.5/images/gdscript-abstract.webp /storage/releases/4.5/images/gdscript-abstract-2x.webp top center-left