Instanced nodes are added to tree - but I can't see them sometimes?

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

Hi there,

I’m working on a game where you are a piece of light roaming around space, absorbing other light and talking to other entities.

Currently, the “sky” is composed of a 3x3 matrix of “starfields” - which are area2D’s the size of the screen. Each “starfield” randomly has stars added to it when it is instanced. To make things are bit more complicated, the starfields are regenerated with a treadmill mechanism, meaning that when the player enters a new starfield, I rejig the “sky” to be a new site of 3x3 starfields. I mention it because it might have something to do with the problem.

The problem?

Sometimes when I launch the game everything works - the sky renders 9 starfields, and each starfield renders some 1-50 stars. Sometimes it doesn’t. In the latter case, all the nodes are added to the tree (they are present when I check in a remote view when the game is running). I’m probably missing some easy way to debug this, but I’m not sure what I could be missing. Could I be using add_child incorrectly?). Here’s a bit of code if it helps (I can add more details or link to some devlogs if additional context is useful):

Sky.gd: extends Node2Dvar rng = RandomNumberGenerator.new()var starfields = []var - Pastebin.com
Starfield.gd: extends Node2Dsignal swap_starfields(matrix_pos)var rng = RandomNumberGe - Pastebin.com

Thanks for any input!