Get_overlapping_bodies() only detecting sometimes?

Godot Version

4.6

Question

I’m having a weird issue. I have a cursor I move like this:

func get_input():
var input_direction = Input.get_vector(“left”, “right”, “up”, “down”)
velocity = input_direction * pointer_speed

func _physics_process(_delta: float) → void:
get_input()
move_and_slide()

I then have an area2d:

func _physics_process(_delta: float) → void:
for coll in $Area2D.get_overlapping_bodies():
if coll is Pointer:
print(“HIT”)
self.visible = true

When going into the menu (pausing the scene tree), the area2d works as normal, but then when moving the cursor outside the area2d, it doesn’t update, and area2d keeps printing HIT. However, when closing and reopening the menu, if the cursor is outside the region, it will stop printing. Basically it seems the cursor’s position only updates when reloading the menu, but I can see it moving and double checked the position is changing. I hope that makes sense. I’m suspecting it has to do with when the area2d polls whats within it at the wrong time, or something with the cursor’s position. Thanks!!

Seems like a much better use of the body_entered signal, the “Your first 2d game” tutorial covers using signals for collisions.

Still if your object moves too fast or your area is too small it can pass over within a frame

1 Like

Tried signals, same issue. I decreased the speed, same thing. Increased the collision size, same thing

What class does Pointer inherit from?

CharacterBody2D

Why are you setting it to visible every physics frame?

That was for testing to see visually if its being activated

I found the reason, when I enable PhysicsServer2D.set_active(true), it works. So it has to do with me pausing the game and physics not be active or something. Any workaround?

Set the Process Mode to Always for the nodes you want to work when the game is paused.

Often when something requires extensive work arounds it means that you approach the problem in the wrong way.

Read the first reply from gertkeno and you will solve the problem quicker and with better results than you’ll do by finding a workaround that makes your solution work … until it breaks and you have to debug.

1 Like