Calling method in instanced scene calls on all instances

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

I have an area2D that is instanced adn when the player enters it, they will go to a level. I do this with a function inside the area2d, but if I call it on one of the instances of it (i have 5) it calls it on all 5. help please!

Here is my code for the area:

extends Area2D

# Declare member variables here. Examples:
export var path : String
var can_warp = false

# Called when the node enters the scene tree for the first time.
func _ready():
	connect("body_entered", self, "enter")
	connect("body_exited", self, "exit")

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if can_warp and Input.is_key_pressed(KEY_Z):
		if (get_overlapping_bodies().size() != 0):
			HUD.enter_id = 0
			HUD.warp("res://level/" + path + ".tscn")

func enter(body):
	can_warp = true

func exit(body):
	can_warp = false

What does it print? Did you try printing the name of the area to check if they are really firing all at the same time? Keep in mind Input.is_key_pressed(KEY_Z) returns true as long as the key is held. You may also check if the destination of the player isn’t itself an area of this kind.

Zylann | 2020-03-19 21:19

I printed the path variable, and yes, it printed all of them

droc101 | 2020-03-19 21:30

Did all of them detected enter and exit properly? i.e is the one your player is on the only one for which can_warp is true?

Zylann | 2020-03-19 21:31

the player is the only other thing on the map besides a tilemap and texturerect

droc101 | 2020-03-19 21:33

Do you have a test project reproducing the issue so I can have a look?

Zylann | 2020-03-19 21:34

I’ll try to make one quick.

droc101 | 2020-03-19 21:36

Well… I Can’t seem to reproduce the bug… And after relaunching the editor it still happens.

droc101 | 2020-03-19 21:45

Ok, it’s NOT detecting exit at all.

droc101 | 2020-03-19 21:50

If i enter and exit all of the areas, it works fine.

droc101 | 2020-03-19 21:52

:bust_in_silhouette: Reply From: droc101

wait one frame…

I’m curious how not waiting a frame would cause all areas to trigger

Zylann | 2020-03-19 22:04

I don’t know. I’m going to switch to a better map system anyways. Thanks for the help

droc101 | 2020-03-19 22:24