Collision callbacks don't fire on embedded Area2D class

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

The area_enter callback works when I create an Area2D node inside the scene editor with a child CollisionShape2D, given a RectangleShape2D, and then having the Area2D node’s area_enter “connected” to a custom function. Again, this way works.

However, if I make a subclass which extends Area2D, I cannot get the area_enter callback to work. I try with the default callback, with a custom function, and I try to check overlapping nodes in the process function. Here’s an example of the code:

class Projectile extends Area2D:
var projSprite
var collShape

func _init(x, y):
	set_process(true)
	
	projSprite = Sprite.new()
	projSprite.set_texture(load("projectile.png"))
	add_child(projSprite)
	set_pos(Vector2(x, y))
	collShape = CollisionShape2D.new()
	var rect = RectangleShape2D.new()
	rect.set_extents(Vector2(10,10))
	collShape.set_shape(rect)
	add_child(collShape)
	connect("area_enter", self, "projectile_enter_area")

func _process(delta):
	translate(Vector2(0, -400 * delta))
	
	if (get_overlapping_areas().size() != 0):
		print("somethinggg overlapping")

func _area_enter(area):
	print("area collision")

func area_enter(area):
	print("area collision")

func projectile_enter_area(area):
	print("custom collision callback")
:bust_in_silhouette: Reply From: Ace-Dragon

You will probably want to use the body_enter(body) callback instead if it’s the projectile object itself you’re checking for (providing it’s able to collide).

:bust_in_silhouette: Reply From: radishes

I believe you are encountering Physic Body Instanced scene doesn't use CollisionShapes · Issue #2314 · godotengine/godot · GitHub.