Godot - Nodeのタイプを取得する
Nodeのタイプを取得するGDScriptのコード例です。
GDScriptではget_class()
にてNodeのタイプを取得する事が可能です。
var node = get_node("Sprite2D")
var node_type = node.get_class()
# Sprite2D
get_class()
で指定した対象がノードではない場合、「Invalid call」エラーが発生します。
var x = 12
var node_type = x.get_class()
# Invalid call. Nonexistent function 'get_class' in base 'int'.
![Godot](/images/godot/image.png)