Why is the one Item dissappearing and the another one not even though it has the same code?

Godot 4.7.1, programming Language GDScript

So, I am a Godot beginner and currently coding my first ever Platformer, but one Item is disappearing, and the another one not.

This is my code for the Mega Coin AND normal Coin:

extends Area2D

@onready var game_manager: Node = %GameManager


func _on_body_entered(body)
 if (body.name == "CharacterBody2D"):
  queue.free()

But the Mega Coin is collectable, and the Coin is not. I don’t know why. Even though its EXACTLY the same!

The name of the second node is probably exactly the same as the first node but with a “2” added to the end. Sibling nodes can not have the same name in the same scene.

I would avoid using names for things like these. Instead add a function like pickup() in the coin, and then call it.

func _on_body_entered(body)

if body.has_method("pickup):

body.pickup()

The pickup function in the coin script could look however you want. The example below would make what happens identical to what you want with your current solution.

func pickup():

queue_free()

Did you connect the area’s signal? Maybe showing your scene tree would help.

I assume the “CharacterBody2D” name is supposed to be your player? That should work for all coins, but it still may be better to use Groups with .is_in_group("player") in case your player node name changes or you add another player.

Oh i thought the player script used the name of the coin nodes, but clearly it is the other way around.

That’s another good reason to change the body.name check to something else, the name isn’t very clear what it’s comparing!

Please show this code in that box, because I’m kinda confused

And also: They are two indenpendent scenes.

Do double check if the signal is connected to the normal coin in the inspector.

Depending on how you saved both scenes, the signal can reset even if there’s no obvious error during runtime.

Well, it turns out the signal is connected

Have you forgotten to change collisions for one of them?

You do that by opening the scene, selecting the area node and going to “Collision”. Compare what you see for the normal coin and the mega coin. If anything you see is different, change it so that the not working scene gets the same as the working scene.

There’s no difference. I send you some screenshots, do you see something off?



There is a difference, the Coin does not have a signal connected

Yes there it is.

For reference, this icon represents a signal is connected to your node. It’s missing from your normal coin scene.

Thanks