Area2D not detecting body under specific circumstances

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ThEnderYoshi

To boil it down, I’m trying to make a bullet collide with a player every frame.
However, the situation is pretty complex, so I’ll try to explain the structure here:

I have a general Battle scene:
enter image description here

There are multiple Encounter scenes.
One is chosen at the start of the battle, then added to CurrentEncounter:
enter image description here

The Encounter node has an Array[PackedScene].
Each PackedScene contains a Wave scene:
enter image description here

Here is a Wave. One is randomly chosen, then added to CurrentWave.
The Bullet node is the Area2D in question:
enter image description here


When the Wave loads, it instances the Player scene, then adds it as a child:

# Part of wave.gd

func _ready() -> void:
    # This is for debugging
    if get_tree().current_scene == self:
        setup()
        start()

func setup() -> void:
    # Called IMMEDIATELY after instancing
    rect_min_size = rect_size
    _create_bounds()


func start() -> void:
    # Called when the player should spawn
    player = SCENE_SOUL.instance()
    add_child(player)
    player.owner = self
    player.position = get_node("PlayerSpawn").position

To collide with the player (KinematicBody2D), the Bullet has this:

# Part of bullet.gd
extends Area2D

# ...

onready var wave: Wave = owner

# ...

func _physics_process(delta: float) -> void:
    if wave.soul in get_overlapping_bodies():
        wave.soul.damage(at)

And here’s how the Wave is loaded in Battle:

# Part of one of Battle's children

func enter() -> void:
    var next_wave = battle.encounter.get_wave()
    next_wave.setup()
    battle.current_wave.add_child(next_wave)
    
    battle.anim.play("show arena")
    yield(battle.anim, "animation_finished")
    
    next_wave.start()

With that out of the way, here’s the problem:

When I run the Wave scene by itself, everything works as expected.
But when I test it in the Battle scene, the Bullet just doesn’t collide with the Player.

(The Bullet’s and Player’s collision layers and masks are compatible.)

Below is a list of things I’ve tried, while getting the same results:

  • Replacing wave.soul in get_overlapping_bodies() with overlaps_body(wave.soul)

  • Using signals

For the record, in the case where it didn’t work, the Player can still collide with physics bodies, just not the Area2D

ThEnderYoshi | 2022-09-04 04:20

:bust_in_silhouette: Reply From: ThEnderYoshi

Ok I figured it out!
It’s because, during battle, the game is paused (so nothing in the overworld is processed)

The Battle scene’s pause_mode property is set to PROCESS, so it’s not affected by the pause. (everything else is INHERIT)

But apparently that means Area2D doesn’t check for collision. Weird…

I guess I never noticed because, when I made the Bullet move through _physics_process(), it moved normally