A change scene script doesn't run when entering an Area2D

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

So I need a regular scene changing area like you’ll find in most 2D RPGs. I already wrote the script but it isn’t working.
This is what I wrote:

extends Area2D

func _on_Area2D_body_entered(body: KinematicBody2D):

and on the Area2D i connected body_entered signal to the player (KinematicBody2D).
Am I doing something wrong?

:bust_in_silhouette: Reply From: SQBX

The player could be of the wrong collision layer. You can change the type of collision layers the Area2D can collide with in the inspector (under “Mask”)

If that isn’t the issue, your scene might not exist. Try adding a print statement in your _on_Area2D_body_entered function to see if it works.

So I tried all of it, both collision layers and mask are matching, the second scene does infact exist and is in the same location as the code says however the message from the print command isn’t showing up in the output. I did however notice that when I connect the signals this apperars in the player script:

func _on_Area2D2_body_entered(body: KinematicBody2D):

Am I supposed to put any code here?

iNeedMentalHelp | 2023-01-03 17:22

Ah, I see the problem. You can delete this function in the Player script:

func _on_Area2D2_body_entered(body: KinematicBody2D):

And repeat the steps for connecting the Area2D. Except, this time, double click the Area2D when it brings up the current tree, so that the signal connects to the Area2D’s script.

SQBX | 2023-01-03 17:35

However if I do so then I will immidiately go to the second scene when i start up the game

iNeedMentalHelp | 2023-01-03 17:40

Could you tell me what the structure of your tree looks like? Is the Area2D a child of the player or completely separate?

Also, could you please tell me what you are trying to accomplish (such as making a door system)?

SQBX | 2023-01-03 19:33

Oh sorry for not replying I didn’t get an email about your reply. The Area2D is completly separate from the player. And yes I am trying to create a door system

iNeedMentalHelp | 2023-01-05 17:56