Label is not displaying text in game

Godot Version

4.2.2

Question

This used to work but I changed from using a signal to just using instantiating for testing purposes. The text of the label does not display in game. The player picks up a card and the text on screen should say 1/1 cards.

I have a label with a script attached that only displays text and takes in two parameters. The text appears in the output thanks to the GD.Print() function.

public partial class AmountLabel: Label
{
public void DisplayScore(int amount, string name)
{
Text = $“{amount}/1 {name}”;
GD.Print(Text);
}
}

The parameters come from the card.cs script.

public partial class Card : Node
{
public int cardAmount = 0;

public void OnCardCollected()
{
    cardAmount++;
    AmountLabel label = new();
    label.DisplayScore(cardAmount, "Card");
}

}

This function is called from the collectable.cs script.

public partial class Collectable : Node
{
public void Collect()
{
Card card = new();
card.OnCardCollected();
QueueFree();
}
}

This collectable script is called from the player.cs script

public void TouchCollectable()
{
for (int i = 0; i < GetSlideCollisionCount(); i++)
{
KinematicCollision3D collision = GetSlideCollision(i);

        if (collision.GetCollider() is Collectable collectable)
        {
            collectable.Collect();
            break;
        }
    }
}

There is text in the Text variable of the label, since it is being displayed in the output, but is not being displayed on screen. The label scene is the normal scene with only the font colour changed.

So, why is the text not displaying in-game?

check how node looks on remote
obraz
when game is running.

Is the dollar sign in $"{amount}/1 {name}" intentional? Never seen that as a C# feature but in GDScript that attempts to retrieve a node path.

is was added in c# 10

I attempted using this:

public partial class AmountLabel: Label
{
public void TextSet(string aText)
{
Text = aText;
}

public void DisplayScore(int amount, string name)
{
    AmountLabel label = new();
    label.TextSet($"{amount}/1 {name}");//= //Text = $"{amount}/1 {name}";
    AddChild(label);
    GD.Print(Text);
}

}

and it still is not working. Bear in mind that the AmountLabel script is attached to the label. What do you mean about assigning AmountLabel a parent, as in a parent node?

is already label don’t needed new copy inside.
I will ask again. Did you check remote? maybe is working but you don’t see?

1 Like

I’m not sure what remote is supposed to do. The amountLabel label is there when i click the remote button while the game is running. Writing text into the text box adds it to the screen, but when I collect the object the text does not change still.

You use remote to check variables… we don’t see your project
This code is works:

using Godot;

namespace LabelTest;
public partial class LabelTest : Node
{
	Label Label { get; set; }
	public override void _Ready()
	{
		Label = new();
		AddChild(Label);
	}

    public void UpdateLabelScore(int score, string name) => Label.Text = $"{score}/1 {name}";
}

tested with Button
obraz

obraz

obraz