Need 2 nodes from 2 different scenes to talk to each other

Godot Version



Hey! New to Godot, and pretty frustrated right now. I’m trying to figure out what seems like it should be incredibly simple, but nothing I’ve tried works. I have 2 “scenes” (a monster and a rock) which I’ve placed in a world scene. The monster has an area2D node, and I need that node to detect when it comes in contact with the rock’s area2D node. But in order for this to happen, the monster needs to be aware of the rock’s existence, and I can’t for the life of me get the monster’s script to communicate with the rock’s area2D node. I’ve tried get_node(node_path), but that only seems to access nodes on the monster’s node tree. I was reading about preloading, but that seems to instantiate a copy of the rock in the scene, and not reference the rock that already exists in the scene. Newbie question, I know, but how do child nodes in different “scenes” talk to each other? Any help I can get would be very appreciated; I just can’t figure out how to have 2 different objects communicate with each other. My monster script is bellow, and the rock doesn’t have a script on it.

extends CharacterBody2D

var obstacle
var rock

@onready var animationPlayer = $AnimationPlayer
@onready var area2D = $"Area2D - object detection"

#trying to access the area2D node on the Rock in the scene. This is my
#attempt at accessing the rock node.
func _ready():
    rock = get_node("Rock")

func _physics_process(delta):


# my attempt at assigning obstacle var to the Rock node's area2D node.
if rock == null:
	print("nothing happened")
	obstacle = rock.area2D

if area2D.overlaps_area(obstacle):
	print("collision detected")

I would use the built-in collision detection of Area2Ds and if you assign the right mask (what the Area2d is looking for) and layer (what it exists on). You can then use the area_entered/area_exited signals to know when they’ve collided.

Or there’s a function like get_overlapping_areas() and you could iterate through everything it’s colliding with.

1 Like

Thank you so much! This is exactly what I needed.