Delete only one instance

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

Hi, I made an arrowUp scene and a timer to spawn. If I press “ui_up” button it’s deleting all the objects that has been added to a world.tscn. What I wanna do is delete one arrowUp scene not all the arrowUp instanced scenes.


var arrowUpScene = preload("res://Scenes/ArrowUp.tscn")

func spawnArrowUp():
	var arrowUp = arrowUpScene.instance()
	arrowUp.speed = randi() % 270 + 990
	arrowUp.global_position = Vector2(hotSpot.position.x + 800, hotSpot.position.y - 15)

func _on_spawnTimer_timeout():
timer.wait_time = rand_range(1, 2)


extends Area2D

onready var anim_p = $AnimationPlayer

var speed = 270
var pressed = false

func _physics_process(_delta):
	if !pressed:
		position.x -= speed * _delta
	if Input.is_action_just_pressed("ui_up"):
		if Global.arrowUpOnHotspot:
			pressed = true"success")
			pressed = true"fail")

func _on_ArrowUp_area_entered(area):
	if area.is_in_group("listener"):
		Global.arrowUpOnHotspot = true

func _on_ArrowUp_area_exited(area):
	if area.is_in_group("listener"):
		Global.arrowUpOnHotspot = false

func _on_AnimationPlayer_animation_finished(anim_name):
	if anim_name == "success":
	if anim_name == "fail":


:bust_in_silhouette: Reply From: estebanmolca

I think the problem is that you are using a global variable as a condition. When you use Global.arrowUpOnHotspot = true you are modifying that variable for all instances that use it. One way to fix this is to create a local variable in the ArrowUp script to use as a condition.