Can't I see if some object extends a custom class without preloading it?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mateusak
:warning: Old Version Published before Godot 3 was released.

I mean, as far as I know, you need to do that:

var class = preload("")

func _ready():
   if object extends class:

Isn’t there another way? One that doesn’t need to allocate a variable to check against?

:bust_in_silhouette: Reply From: Zylann

There is no way of doing that without loading the class.

However, you should use const instead of var, this way the class won’t be fetched for every instance of your script.

Note: preload doesn’t loads the resource everytime, it does it only once when the script is loaded, and embeds a reference to that resource wherever you store it (var or const).