Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to get class name string from Reference #4708

Open
filantus opened this issue Jun 20, 2022 · 1 comment
Open

Ability to get class name string from Reference #4708

filantus opened this issue Jun 20, 2022 · 1 comment

Comments

@filantus
Copy link

filantus commented Jun 20, 2022

Describe the project you are working on

General GDScript improvements.

Describe the problem or limitation you are having in your project

For now it's not possible to get class name string (custom, not RefCounted) from Reference object out of box.

I found it's already has been discussed in Q/A:
https://godotengine.org/qa/50783/get-class-name-as-string-from-class-reference
https://godotengine.org/qa/46057/how-to-get-the-class-name-of-a-custom-node

But still not implemented.

Of course it can be workarounded with custom variable or function. But it's would be much more convenient if it's will be awailable out of box.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Described above.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For example through some property or function like get_custom_class()

class MyClass:
	pass

class MyChildClass extends MyClass:
	pass

func _ready():
	print(MyClass.new().get_custom_class()) # will print out: MyClass
	print(MyChildClass.new().get_custom_class()) # will print out: MyChildClass 

If this enhancement will not be used often, can it be worked around with a few lines of script?

Yes, it's can be workarounded by custom variable like this:

class MyClass:
	var _class_name: String = 'MyClass'

class MyChildClass extends MyClass:
	func _init():
		_class_name = 'MyChildClass'

or by custom function like this:

class MyClass:
	func _get_class() -> String:
		return 'MyClass'

class MyChildClass extends MyClass:
	func _get_class() -> String:
		return 'MyChildClass'

But that is tedious enough.

Is there a reason why this should be core and not an add-on in the asset library?

Beacause it's a GDScript core improvement

@Calinou
Copy link
Member

Calinou commented Jun 20, 2022

Related to godotengine/godot#21789.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants