Need help with Area3d detecting collisions late

Godot Version

4.3.stable

Question

How do I make a “on_…_area_entered” function get called immediately when starting my scene? I need to detect collisions of 2 child Node3D scenes as soon as the scene starts, not 1, 2, 3, 4, etc frames after. I have logic depending if the 2 scene’s areas are touching each other. Is there a faster way to detect collisions of an area?

the children scenes code:

extends Node3D

#list that pools all pivot nodes in scene
@export var pivot_pool : Array[Pivot]

#list of pivot nodes to add to pivot pool
var pivots_to_pool : Pivot

var is_room_intersecting : bool = false

#--------------------------------------------------------------------

@onready var occupying_space: Area3D = $OccupyingSpace

#--------------------------------------------------------------------

func _ready():
_create_timer_for_pivot_intersecting()
check_if_room_intersecting(is_room_intersecting)

func _on_occupying_space_area_entered(occupying_space: Area3D) → void:
is_room_intersecting = true
print(“room entered area room”)

func _on_occupying_space_area_exited(occupying_space: Area3D) → void:
is_room_intersecting = false
print(“room exited area room”)

func check_if_room_intersecting(bool):
if is_room_intersecting == true:
print(“rooms are intersecting”)
return true
if is_room_intersecting == false:
print(“rooms are not intersecting”)
return false

func _create_timer_for_pivot_intersecting():
await get_tree().create_timer(.01).timeout


the main scene code:

extends Node3D

var picked_scene : Node3D

var can_spawn_room : bool = true

@onready var lvl_gen = $“.”

func _ready():
doesnt_matter()
check_if_room_intersecting(can_spawn_room)
if can_spawn_room == false:
print(“willnotwork”)
elif can_spawn_room == true:
print(“willwork”)

func doesnt_matter():
for child in lvl_gen.get_children():
picked_scene = child

func check_if_room_intersecting(bool):
_create_timer_for_pivot_intersecting()
if picked_scene.check_if_room_intersecting(true):
return false
elif picked_scene.check_if_room_intersecting(false):
return true

func _create_timer_for_pivot_intersecting():
await get_tree().create_timer(.01).timeout



I kind of understand what you are looking to implement, but can you describe your use case scenario? And expand on what the desired behavior is?

thank you for your response.
ok so i want to make a level generator that will random spawn prefab rooms from an array onto pivot nodes (Node3Ds) once the scene starts. this specific scene is a minimal debug version only to test rooms colliding with each other. my desired behavior is to detect the room’s area colliding with another room’s area before any other function can be called. in the screenshots, the 1st pic has the rooms intersecting (areas overlapping) but my test functions are calling as if the areas were not colliding, but at the end “…entered area” finally says they are, and by then the test functions have already called as if the areas were not intersecting. in the main level generator scene, i have functions depending on whether or not an instantiated room is colliding with another room. if the rooms are intersecting, rotate the y axis by 90 for a maximum of 3 times or until the rooms are not colliding. if still colliding after the 3rd time, another room from an array containing rooms will be picked and will repeat the process. i tried using a timer so the dependent functions can wait for “…entered area” but that didn’t work.
let me know if that made sense, im still learning.

this is a screenshot of the main level generator. this is the type of result im looking for

but half the time the rooms spawn like this

For your room placement use AABB(s) or Plane(s) or a grid raster to detect what overlaps and what not or similar “instant result” things.

An Area3D Node and physics in general is the wrong use for this as physics requires sync points done in the physics process callback. Nothing about physics is ever “instantly updated”. The area body entered signals are actually the earliest you can get a current state from physics because it is directly called after the physics update.

2 Likes