Godot 4.1, emit signal won't work
Asked Answered
R

2

0

Good day, I'm new to godot. I am working on a platformer game where all dna card(collectables) are all queued free, a gate will open for the next level but I am confuse why the emit signal won't work even all the collectables are queued free.

So this the code where the all queued free collectables counted and send signals(I think)

`extends Area2D

signal rockon

func _on_body_entered(body: PhysicsBody2D):
queue_free()
var dna = get_tree().get_nodes_in_group("dna")
if dna.size() == 1:
emit_signal("rockon")`

And this the code for opening the gate. This script is on my root node of the scene

`extends Node2D

func _ready():
$dna.connect("rockon", asdf)

func asdf():
$gate.queue_free()`

Rimini answered 2/12, 2023 at 17:46 Comment(0)
G
2

Rimini In the editor open the Debug menu and enable "Visible Collision Shapes", try your game again and check if your Area2D is behaving as it should. You call queue_free() once something collides with your area, so chances are that you remove your area too early.

Glycoprotein answered 2/12, 2023 at 18:7 Comment(0)
B
0

Loutish Mark Toxe's answer as "best answer" if it fixed your bug 🙂
To specify, move "queue_free()" to the bottom of your body_entered function.

Broth answered 26/12, 2023 at 18:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.