Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Area2D fires off "body entered" signal when scene is added back to scene tree #38293

Closed
golddotasksquestions opened this issue Apr 28, 2020 · 4 comments

Comments

@golddotasksquestions
Copy link

golddotasksquestions commented Apr 28, 2020

Godot version: 3.2.1

OS/device including version: Win64

Issue description:
area2d_remove_bug

I have 3 scenes. A main Scene that has the a level as child and manages the adding and removing of levels, and two levels: a red level and a green level. The red_level gets removed and re-added every time, the green_level(s) gets instanced, added and then queued free.

The weird thing is whenever the red_level gets added back to the SceneTree, the Area2D detects the player body, even though I have set the position of the player body away from the Area before even removing the red_level scene.

This is a bit difficult to explain, best to look at the minimal project.

If makes no difference if the signal_next_level is call_deferred() or not.

func _on_AnimationPlayer_animation_finished(_anim_name):
	$player.position = Vector2(128, 256)
	stage_number += 1
	$Label.text = str("stage ", stage_number)
	$Area2D/ColorRect.modulate.a = 1.0
	call_deferred("emit_signal","signal_next_level")

What does make a difference though, is to yield timeout before the signal is emitted, but only if the timeout is long enough as user "sushi" on Discord figured out:

func _on_AnimationPlayer_animation_finished(_anim_name):
	$player.position = Vector2(128, 256)
	stage_number += 1
	$Label.text = str("stage ", stage_number)
	$Area2D/ColorRect.modulate.a = 1.0
	yield(get_tree().create_timer(0.1), "timeout") #0.01 would have no effect
	call_deferred("emit_signal","signal_next_level")

Possibly related issue:
#34085
also possibly related: #27441 (comment)

Steps to reproduce:
Walk the player into the area in the middle.

Minimal reproduction project:
Area2D_enter_on_remove_bug.zip

@Zireael07
Copy link
Contributor

IIRC we had a related issue for 3D and the problem was the things are instanced at origin for a fraction of a second...

@golddotasksquestions
Copy link
Author

golddotasksquestions commented Apr 28, 2020

@Zireael07 What do you mean by "things"? The Area too? This seems like really unclean and unreliable behavior to me. I would understand if it's in the same frame, but this I don't understand.

@t-karcher
Copy link
Contributor

I'm pretty sure that's a duplicate of #14578 .

@Calinou
Copy link
Member

Calinou commented Apr 28, 2020

Duplicate of #14578.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants