func get_class_name(object: Object) -> String:
if not object:
return type_string(TYPE_NIL)
var script: Script = object.get_script()
var object_name := script.get_global_name() as String if script else object.get_class()
if object_name.is_empty():
var script_path := script.resource_path
if script_path.is_empty():
push_error("Cannot get class name from inner classes")
return script_path
return object_name
This is what I use to get any object class as a String (or the path to the script, if it has no name). Note that there is currently no way to get inner class names (anything declared with class instead of class_name).
Also, it doesn’t really matter how performant this is, since you’re probably not gonna be calling it 1000 times a frame.