Hallo everyone! So, I am trying hard to make an Area2D check on an explosion of a projectile.
I would love to create a "utils" func to call from signleton for all the possible explosions, so I did create a func in an Autoload script called explosion(impactpos, radius)
The func will be called by another node which will be queuedfree on impact. So far I have the following not working at all:
(in utils.gd, Autoloaded)
func explosion(impact_pos, radius):
var area = Area2D.new()
var shape = CircleShape2D.new()
var body_list = area.get_overlapping_bodies()
for i in body_list:
note: basenode() is a func in utils which calls the base node from getroot().gettree().getchild(-1)
With this code, body_list is always empty.
Additional infos: I have used the method .getoverlappingbodies() successfully for other purpouses. Attached to a node with an editor-created Area2D + CollisionShape with exactely the same bodies (which are rigid bodies), I used this method outside _process and was working as charm. No Area2D.new() and no "area2d.tscn".instance(), so I guess the issue should be here somehow.
Updates: I have also tried to attach this func in the script (and node) which is calling it. No luck.
Plus: I have also tried to create an explosion.tscn external scene, which has an Area2D as base node and an editor-created CollisionShape. So instead of using:
area = Area2D.new()
i called for the instanced scene:
area = load("res://explosion.tscn").instance()
No luck either way. The body_list is still always empty even if I can finally see the Area2D on "enable visible collision" mode.