I was helping another guy with his Flappy Bird clone, and I ended up making the entire project based on what he gave me. I kind of solved the issue by respawning the pipes a different way, but it still bugs me why I couldn't get it to work the original way he intended, and now I've tried to do it again, and come down to some behaviour that I can't explain. When the one of the Pipe's area2d nodes hits the Deleter area2d, it should get the root node of the Pipe and queue_free() it, then respawn a new Pipe. But when the second Pipe goes through the Deleter, it can't find the Pipe root node, so it doesn't get deleted and it also doesn't spawn a new one. WHY???
Original help post for the other guy: https://discord.com/channels/212250894228652034/1108032682727854161
#Why is the pipe not being deleted and respawned?
7 messages · Page 1 of 1 (latest)
world.gd with extra parts removed
extends Node2D
var Pipe = preload("res://pipe.tscn")
var Bird = preload("res://bird.tscn")
var bird_instance: Bird
var pipe_instance: Pipe
var score = 0
func _ready():
spawnBird()
spawnPipe()
get_ready()
func get_ready():
$GetReadyText.show()
get_tree().paused = true
$GetReadyTimer.start()
func _process(delta):
pass
func spawnPipe():
pipe_instance = Pipe.instantiate()
pipe_instance.position = Vector2(%PipeSpawn.position.x, %PipeSpawn.position.y + randf_range(-60, 60))
pipe_instance.find_child("Gap").connect("area_exited", Callable(_on_gap_area_exited))
bird_instance.connect("bird_dead", Callable(pipe_instance.on_bird_dead))
add_child(pipe_instance)
func _on_deleter_area_entered(area: Area2D):
print(area.name, " area entered, ", area.get_instance_id())
var pipe = area.find_parent("Pipe")
if pipe:
print("Pipe found")
if pipe and not pipe.is_queued_for_deletion():
pipe.queue_free()
call_deferred("spawnPipe")
print("Pipe ID: ", pipe.get_instance_id(), " destroyed")
I added some more debugging code, and now this is what it prints out:
Pipe spawned
Top area entered, 31138514115
Pipe found
Parent found, Pipe
Pipe ID: 31121736898 destroyed
Bottom area entered, 31188845766
Pipe found
Parent found, Pipe
Pipe spawned
Top area entered, 47127201056
Parent found, @Pipe@2
Bottom area entered, 47177532706
Parent found, @Pipe@2```
func spawnPipe():
pipe_instance = Pipe.instantiate()
pipe_instance.position = Vector2(%PipeSpawn.position.x, %PipeSpawn.position.y + randf_range(-60, 60))
pipe_instance.find_child("Gap").connect("area_exited", Callable(_on_gap_area_exited))
bird_instance.connect("bird_dead", Callable(pipe_instance.on_bird_dead))
add_child(pipe_instance)
if pipe_instance:
print("Pipe spawned")
func _on_deleter_area_entered(area: Area2D):
print(area.name, " area entered, ", area.get_instance_id())
var pipe = area.find_parent("Pipe")
var parent = area.get_parent()
if pipe:
print("Pipe found")
if parent:
print("Parent found, ", parent.name)
if pipe and not pipe.is_queued_for_deletion():
pipe.queue_free()
call_deferred("spawnPipe")
print("Pipe ID: ", pipe.get_instance_id(), " destroyed")
```
So I changed the area.find_parent("Pipe") to match anything with "Pipe" in it, area.find_parent("*Pipe*")
this is now what happens:
Pipe spawned
Bottom area entered, 31188845766
Pipe found
Parent found, Pipe
Pipe ID: 31121736898 destroyed
Pipe spawned
Top area entered, 41305507057
Pipe found
Parent found, @Pipe@2
Pipe ID: 41288729851 destroyed
Bottom area entered, 41355838711
Pipe found
Parent found, @Pipe@2
Pipe spawned
Top area entered, 41641051331
Pipe found
Parent found, Pipe
Pipe ID: 41624274164 destroyed
Bottom area entered, 41691382982
Pipe found
Parent found, Pipe
Pipe spawned
Top area entered, 41892709617
Pipe found
Parent found, @Pipe@3
Pipe ID: 41875932411 destroyed
Bottom area entered, 41943041271
Pipe found
Parent found, @Pipe@3
Pipe spawned
Top area entered, 42110813379
Pipe found
Parent found, Pipe
Pipe ID: 42094036212 destroyed
Bottom area entered, 42161145030
Pipe found
Parent found, Pipe
Pipe spawned
Top area entered, 42328917233
Pipe found
Parent found, @Pipe@4
Pipe ID: 42312140027 destroyed
Bottom area entered, 42379248887
Pipe found
Parent found, @Pipe@4
Pipe spawned
Top area entered, 42513466563
Pipe found
Parent found, Pipe
Pipe ID: 42496689396 destroyed
Bottom area entered, 42563798214
Pipe found
Parent found, Pipe
Pipe spawned
Top area entered, 42815456497
Pipe found
Parent found, @Pipe@5
Pipe ID: 42798679234 destroyed
Bottom area entered, 42865788151
Pipe found
Parent found, @Pipe@5
Pipe spawned
Top area entered, 43083891907
Pipe found
Parent found, Pipe
Pipe ID: 43067114747 destroyed
Bottom area entered, 43134223558
Pipe found
Parent found, Pipe
Pipe spawned
Bottom area entered, 43385881847
Pipe found
Parent found, @Pipe@6
Pipe ID: 43318772930 destroyed
Pipe spawned```