Why are all of my objects disappearing at the same time?

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

I have more than one item in my 3D game(e.g. an apple and a wood block) that are set up so that when the player enters each seperate area, that item disappears. I also have an overlay that has a counter for each one. The problem is that when the player collects the apple, everything else disappears at the same time and all the counters go up. I only want one item to be able to be collected at a time. What am I doing wrong?

Could you explain, in detail, how the scene is setup? For example, show us the scene tree, or some of the code involved?

Ertain | 2021-07-16 18:03

Hi Ertain,

Sorry about the lack of detail. In regards to the scene tree, here’s how it’s setup:

In regards to the code, an example of what I have for the items being connected to the Player, is:

func _on_apple_body_entered(body):
if body.name == “player”:
$Timer.start()

The Timer’s Timeout function was also connected to each item, and a signal was emitted, such as:

*extends Area

signal applecollected

func _ready():
pass # Replace with function body.

func _on_Timer_timeout():
emit_signal(“applecollected”)
queue_free()*

I also went and connected the emitted signal to the counter for each item, for example:

*extends Label

var apples = 0

func _ready():
text = String(apples)

func _on_apple_applecollected():
apples = apples + 1
_ready()*

Danielle’sgames | 2021-07-17 03:56

Thank you for providing the details. Could you please properly Markdown your code? It’s a bit hard to read.

Ertain | 2021-07-17 04:41

Yes, of course. The first code is:


func _on_apple_body_entered(body):
    if body.name == "player":
	   $Timer.start()

The second code is:

extends Area

signal applecollected

func _ready():
   pass 


func _on_Timer_timeout():
      emit_signal("applecollected")
      queue_free()

The third code is:

extends Label


var apples = 0

func _ready():
     text = String(apples)


func _on_apple_applecollected():
         apples = apples + 1
               _ready()

Danielle’sgames | 2021-07-17 05:09

How are the signals for the apple, rainblock, and wood objects connected? Do they listen to the correct signal, i.e. the woodblock node only listens to the signal for the “wooblock collected” signal? Are some of these objects duplicates of each other? Also, is only one timer used for all of the objects?

Ertain | 2021-07-17 20:06

Hi Ertain,

Thank you for replying back. I was using one timer for everything, but I went and made it so two of the objects had there own timers, as well as connected the object to itself, and now each of those objects are disappearing on their own. Now I just have to do the same with the rest of it. Thank you so much for the help.

Danielle’sgames | 2021-07-18 04:08

:bust_in_silhouette: Reply From: Guliver_Jham

I don’t know, you didn’t give us even a little example of code.