+2 votes

I have created a custom node like below

extends Area2D
class_name CollisionArea

func _ready():
    connect("area_entered", self, "on_area_entered")

func on_area_entered(var area):
    print( area.get_class() )

when ever 2 CollitionArea nodes collides it prints "Area2D" but I want the custom class name ( CollisionArea ) to be printed, is there any way to get the name? (i don't want to use the node.get_name() because names often change)

in Engine by (251 points)

Have you tried "Object.get_class()" ?

1 Answer

+7 votes
Best answer

get_class() always returns the name of the native class. It's easy to change this behaviour by overriding the method in your custom node:

func get_class(): return "CollisionArea"

See https://github.com/godotengine/godot/issues/21789 for a discussion about this behaviour and ideas on how to change it in the future.

by (1,696 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.