0 votes

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()
Godot version Godot Alpha 9
in Engine by (18 points)

1 Answer

0 votes

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!

by (418 points)
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 Frequently asked questions and 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 [email protected] with your username.