I have a simple game which the main plot is two display RigidBodies (using visible = true), two at a time. After they are gone, due to the action performed by the player, another pair shows up. This scheme should go on as long as I support the RigidBodies. In the game structure, all RigidBodies are contained in a Control node. When I start the game, in the I create the list of nodes by invoking $Control.get_children() and passing it to the onready variable node_list (onready var node_list + $Control.get_children())
So far I have:
ROOT-
|
Control -
|
RigidBody_1
RigidBody_2
(...)
RigidBody_6
To show the node during game play I just have a simple function, node_show(), which code is as follows:
func node_show():
node_1 = node_list.pop_front()
node_2 = node_list.pop_front()
node_1.visible = true
if node_1.visible == true:
iteration +=1 # A chec to count number od displayed nodes
node_2.visible = true
if node_2.visible == true:
iteration +=1
Each time the RigidBody is triggered by the player in the scene, it plays an animation which, through the animation_finished native godot signal, triggers the self.queue_free() function to remove the node from the tree, free the game canvas and also pass a signal to the main scene that the node_show() can start and pick two new node from the list.
So basically, I though it would work but it really behaves extremely funny.
As initially the node_list contains six rigid bodies, the first run of the nod_show(), creates two nodes, 1 and 2, leaving the list with four RigidBodies, simple. The game goes, I react with the RigidBodies in the scene, they are removed and the node_show() is triggered to access the list, now with just four RigidBodies, passing two new nodes to the main scene and leaving two last nodes in the main node_list. But now what I see is something like this:
node_list = {[RigidBody2D:1315], [Deleted Object]]
Somehow the list has deleted bodies there, why would that happen? I would gladly welcome an at least hypothetical explanation as I believed this should be super simple but I can't pass this issue by myself. Is there a better way to approach such simple handling of nodes?