When a node is added, it is not visible when the game is ran

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

I have a Grid, which extends TileMap, and I’m trying to spawn panels in. Panels extend Area2D.

The hierarchy:
Main scene → player grid scene → grid scene → [player scene, x number of panel scenes (added via spawn_panels function)].

Please note that these are all the above are added in the 2D editor, and only the panels are added via script.

To spawn the panels, I have this function ran in _ready in Grid:

func spawn_panels(charType):
  var panelInit = null
  var panel = null
  var childPanel = null

  if charType == PLAYER:
	  panelInit = AllyPanel
  elif charType == ENEMY:
	  panelInit = EnemyPanel

  for x in grid_s_x:
	  for y in grid_s_y:
		  panel = panelInit.new(x, y)
		  self.add_child(panel)
		  panel.set_owner(self)
		  panel.set_name("panel" + str(x) + str(y))
		  panel.position = map_to_world(Vector2(x, y)) + cell_size / 2

However, the panels are not visible when the game is ran. I have printed the tree and can see that they are added properly, and also verified that they are not added out of bounds as I’ve hard coded their position to 0, 0 and the player position (player is visible) but it is still not visible.

Any help is appreciated, thanks!

what does the panelInit.new() function do?

RedBlueCarrots | 2020-09-06 03:29

it makes a new instance of it I believe.

Conanap | 2020-09-06 03:40

:bust_in_silhouette: Reply From: Conanap

Turns out adding a .new() instance doesn’t work, so you must either preload or load your scene, call .instance() in order for it to show up when you add it.