How to detect Area2D collision from different scene

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

I am making a 2D sidescrolling shooter and just got the code to shoot a bullet working. I created a second scene named “Bullet” with an Area2D, a sprite and a collision box as a child of area2d. I have a player script in my main scene
Code for the Area2D node:

extends Area2D


 func _ready():
    pass

 func _physics_process(delta):
    position.x += 10

Code for the player (only shooting part)

onready var BULLET = preload("res://Bullet.tscn")
func _process(delta):
    if Input.is_action_just_pressed("shoot"):
        var bullet = BULLET.instance()
        get_node("/root/Game").add_child(bullet)
        bullet.global_position = $Position2D.global_position

I would like the bullet to get deleted when colliding with any objects in my game (This mainly includes a tileset with collision detecion). I read you could link body_entered with a body of your choice, but the tileset is in the main scene and its nodes are not listed under the node tab.

How do I go about detecting collision for this Area2D in another scene?

:bust_in_silhouette: Reply From: Inces

Few options to approaching this

Providing You want to queue bullet free on ANY collision, easiest option is to script bullet himself. Connect his own on_body_entered to himself, and queue him free when it is triggered. You dont need references for anything for this. And even if You wanted to know what are You colliding with it is still possible, because on_body_entered is passed with (body) argument, which You can check if

is TileMap #this is how You check class names

Queuing free is almost always function that should be called by node that is supposed to be queued free, not by other instances