Labels added trough code aren't showing up

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

I’ve been trying to create a combat log for my project. For this I made a scroll container with a vbox container as it’s child, and added labels as children to the vbox container. For this work as I wanted the labels had to have autowrap On and a fixed minimun size.

This system functions with labels that I add in manually, but every label that I add in through code simply doesn’t show up. I’ve done some testing and the labels seem to be added as children correctly, but you can’t see them when the game is running. Also, with the exeption of the label I’m adding in the ‘ready()’, every time I try to add another I get this error:

E 0:00:04.947 add_child: Can’t add child ‘@@2’ to ‘VBoxContainer’, already has a parent ‘_h_scroll’.

:bust_in_silhouette: Reply From: Zylann

Given the message, it looks like the node you are trying to add already has a parent. Make sure you use add_child only once per label. It’s possible you have a problem in your code (I’ve seen this mistake before) where you keep adding the same label?

:bust_in_silhouette: Reply From: VF_Miracle

I think I figured it out. The error was being caused because I had created a global variable that had a label with all the modifications to the properties already done, and I was assigning it to the local variables I was using in my functions. Because of that I wasn’t creating new labels, but rather changing the text and trying to change the parent of the same label.