Can anyone see why children added to this HBoxContainer don't show?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robster
:warning: Old Version Published before Godot 3 was released.

I have the tree as:

Root
- gameLevel
-- HUD
---HBoxContainer

This is the code:

func drawLifeIndicators():
	var containerBox = get_node("HUD/HBoxContainer")
	var scene = load("res://batMini.tscn")
	var newBatMini
	for i in range(0, globals.lives):
		newBatMini = scene.instance()
		print("adding mini")
		#containerBox.add_spacer(true)
		containerBox.add_child(newBatMini)

If I check the inspector, yes, all 3 (in this case) life indicators show up as direct children of the HBoxContainer, BUT they all appear to be showing up in the same physical place. Can anyone see why they’re being generated in the same position?

What node types are your “life indicators”? If they are not Control-based (ie a ‘green’ node), they won’t align themselves within a container.

YeOldeDM | 2017-04-24 17:06

Yes you were correct. I changed it to a control base and it NEARLY worked. Then by adding volzhs’s answer to the solution it all came together. Thanks for the help.

Robster | 2017-04-25 03:36

:bust_in_silhouette: Reply From: volzhs

I guess root node of batMini.tscn is just Control node.
try to set min size of it in batMini.tscn
or set it with code newBatMini.set_custom_minimum_size(Vector2(width, height))

Thank you, with a combination of your answer and YeOldeDM’s answer it worked. Much appreciated.

Robster | 2017-04-25 03:35

:bust_in_silhouette: Reply From: Gollum

I have a similar problem but I could not solve it in code. But if you do it manually select ‘Size Flags’ → ‘Horizontal’: ‘Expand’. You will see that it is arranged in order.