Skip to content

"Expected Area" error in collision_event_callback when repeatedly entering/exiting Area2D across scene transitions #951

Description

@Rodox84

Plugin version: 0.8.32 (single-simd-parallel / Fast SIMD build)
Godot version: [4.6.3]

Description

I'm getting a recurring error in the console:

godot_rapier::spaces::rapier_space_callbacks::::collision_event_callback: Expected Area.

<C++ Source> src\spaces\rapier_space_callbacks.rs:175 @ godot_rapier::spaces::rapier_space_callbacks::::collision_event_callback()

This happens specifically when repeatedly entering and exiting an Area2D used for scene/level transitions, across multiple scene loads/unloads.

Setup

I have an Area2D (LevelTransition) used to trigger scene changes when the player enters it. The area's CollisionShape2D is enabled/disabled via set_deferred:

func _ready() -> void:
    collision_shape.set_deferred("disabled", true)
    body_entered.connect(_player_entered)
    await LevelManager.level_loaded
    collision_shape.set_deferred("disabled", false)

func _player_entered(_p: Node2D) -> void:
    LevelManager.load_new_level(level, target_transition_area, get_offset())

The parent Level scene is freed via queue_free() after the transition:

func _free_level() -> void:
    PlayerManager.unparent_player(self)
    queue_free()

Steps to Reproduce

  1. Create a Level scene with a LevelTransition (Area2D) that loads another Level scene on body_entered.
  2. Move the player in and out of the transition area, going back and forth between two levels, multiple times in a row.
  3. The error appears in the console after a few transitions.

Notes

  • This does not break gameplay functionality — the level transition still works correctly.
  • Originally I was toggling monitoring/monitorable directly on the Area2D, which caused the same error more consistently. Switching to collision_shape.set_deferred("disabled", ...) reduced — but did not eliminate — the issue.
  • The error seems related to a collision event callback firing for an Area2D/CollisionShape2D that may have already been freed or is mid-transition between physics states during scene reload.

Happy to provide a minimal reproduction project if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions