Get class name as string from class reference?

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

If I define a class:

class_name MyClass

How do I get the name of it as a string in another script from the class reference?

var name = MyClass.? # Want "MyClass" string
:bust_in_silhouette: Reply From: Vrzasq

Seems like this is impossible currently in gdscript.
But You can workaround it either by impelemntic static func that will return class name or use get_class() method on instanace of the object. More details here how to get the class name of a custom node - Archive - Godot Forum

Implementing static function to return class name, although requiring adding that function to every script declaring itself as a class, works.

goshot | 2019-09-05 16:06