Last created PackedScene doesn't handle input

Godot Version



I have a packed scene consisting of:

 Cluster: Node2D
 | - clickArea: Area2D
   | - col: CollisionPolygon2D

clickArea has input_pickable set to true

I also have a simple PackedScene called “Soldier” with a RigidBody2D.

I am adding the “Soldiers” into the Cluster and then I calculate the new CollisionPolygon so that I can handle clicking anywhere inside of it to select the cluster of Soldiers.

func _process(_delta):
	var points = PackedVector2Array()
	var children = get_children()
	for child in children:
		if child is Soldier:
	var hull = # quick hull algorithm
	if hull.hull.size() > 3:

Here is the code that creates the Cluster and adds Soldiers to it:

var cluster = pc_soldierCluster.instantiate() as Cluster
for i in range(0, soldiersToSpawn):
	await get_tree().create_timer(randf()*0.2).timeout
	var soldier = pc_packedSoldier.instantiate() as Soldier

cluster’s add_cluster:

func add_soldier(s:Soldier): =

and I have clickArea’s input_event connected to the Cluster’s

func _on_click_area_input_event(viewport, event, shape_idx):

The weird thing is, the latest created area’s input won’t work.

I create 3 Cluster objects and 2 of them work as intended printing event but the latest created one won’t. What is happening here?

Yes, I tried showing collisions and everything works as intended there.


Okay, the problem was that the set_polygon function was inside the _process instead of _physics_process function which caused this weird behaviour

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.