How to set/infer type from get_overlapping_areas()?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By stryker31313

Lets say you have an area.

var area = $Area3D

You can get a list of the areas and set them to a var, using…

var areas = $Area3D.get_overlapping_areas()

Now, you can specify the type array

var areas : Array = $Area3D.get_overlapping_areas()

However, lets say you had a custom class, and this area was only set to look for these classes

var areas : Array[CustomClass] =  $Area3D.get_overlapping_areas()

This does not work, and will through an error in the editor.

I wanted to know if it is possible to do something like this?

var areas : Array[CustomClass] =  $Area3D.get_overlapping_areas()
:bust_in_silhouette: Reply From: Pomelo

I dont know if its possible in that way. I would say no, since if you use get_class() or is_class("CustomClass") on custom classes, it would return the class it inherits from and false, respectivly.

I remember that when i had to get this information, I used to do write this on the custom class, to overwrite the inherited methods:

func get_class():
    return "CustomClass"

func is_class(class):
    if class == "CustomClass":
        return true
    else:
        return false

Once that is done maybe it could work? if not, I would go with:

for area in $Area3D.get_overlapping_areas():
    if area.is_class(CustomClass): areas.append(area)

Hope it helps!