+1 vote

Hi!

How can I name my classes so that I can get them as string with a function?
I see two problems: either I don't know how to properly name my classes, or I don't use the right function/method to get the class as string.
This is what I do for now, which outputs "Reference".

class alpha:
       var v1
       func _init(v1):
         self.v1 = v1

var a = alpha.new(1)
print(a.get_class()) ---> Reference
in Engine by (87 points)

1 Answer

+1 vote
Best answer

https://github.com/godotengine/godot/issues/21789

https://godotengine.org/qa/46057/how-to-get-the-class-name-of-a-custom-node

According to the answer in the last link, your example would look like this:

class alpha:
       var v1
       func _init(v1):
         self.v1 = v1
      func get_class(): return "alpha"

var a = alpha.new(1)
print(a.get_class()) # ---> "alpha"
by (2,060 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.