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?