Label not Working

Godot Version

4.6

Question

Hello!!

I have this label thats supposed to show when an area is entered, and it is detecting my player. When i try to call a ‘show’ on the label when i have an on area entered, though, it isnt showing up. any thoughts?

extends Area2D
@onready var label = $"../../CanvasLayer/Label"


func _on_area_entered(area: Area2D) -> void:
	label.show()
#it prints when i put a print function here


func _on_area_exited(area: Area2D) -> void:
	label.hide()

Is the CanvasLayer visible?

1 Like

Are all of the parents of the label visible? If one is hidden then the label will be too.

Are all of the parents of the label visible? If one is hidden then the label will be too.

It could be the CanvasLayer, or a parent of the canvas layer, or the parent of that, etc.

1 Like

yeah, it is :smiley:

You may have to share a screenshot of your scene tree for us to better understand the problem

1 Like

And a screenshot of the label too. Is it the same color as the background? Is it hidden behind another node?

1 Like

If you have code elsewhere that hides this Label can you show us it and try disabling it?

1 Like

Yeah that’s super weird. Based on what you’re showing us, it should be visible.

all the other code i have is my player movement script which ill put right here:

extends CharacterBody2D

var max_speed = 350
var last_direction = Vector2(1,0)

func _physics_process(delta: float) -> void:
	var direction = Input.get_vector("left_arrow", "right_arrow", "up_arrow", "down_arrow")
	velocity = direction * max_speed
	move_and_slide()

But when i clicked back into the area2d (that makes the label visible) i got this warning?

[Ignore]Line 5 (UNUSED_PARAMETER):The parameter “area” is never used in the function “_on_area_entered()”. If this is intended, prefix it with an underscore: “_area”.
[Ignore]Line 9 (UNUSED_PARAMETER):The parameter “area” is never used in the function “_on_area_exited()”. If this is intended, prefix it with an underscore: “_area”.

Other than that script and obviously the area script thats supposed to turn on and off the label, theres nothing else.

Where’s the area node? I don’t see it in your scene tree screenshot.

1 Like

oop sorry! here it is, its parented to the door:

1 Like

I had experience with this before. Take the Area2D out of the StaticBody2D, this configuration won’t behave properly. Put the area2D outside of the Staticbody in your scene tree and try again.

1 Like

Could there be something wrong with anchors causing it to be off screen? Try adding a print for it’s position to make sure it’s where it should be.

Where are you expecting the label to appear? Can you zoom out and show us the 2D view in editor? Maybe a mock up of what you expect to happen?

okay wait, so i added the ‘position’ thing to the label script now like this:

extends Label

func on_ready():
	print(position)

and now the area script is giving me this error (im just thankful its doing smth atp lol): Attempt to call function ‘show’ in base ‘null instance’ on a null instance. Its giving me it right here:

extends Area2D
@onready var label = $"../../CanvasLayer/Label"


func _on_area_entered(area: Area2D) -> void:
	label.show()

I usually would know how to fix it but me reputting in the node path to the variable didnt work.

on_ready isn’t an override, you probably mean to use _ready.

These parent paths (anything with "../") should be avoided, using an @export or groups would be better.

Does your player have an Area2D node? Keep in mind the area_entered signal only detects other areas, not CharacterBodies, maybe you mean to use the body_entered signal?

my charecter does have a area 2d node yeah :smiley:

also i changed it to ready and its still giving me the same error