It is not clear from the forum UI, but it looks like you were replying to me instead of @anon45973056.
If you were adding to @anon45973056 response, then what you said is true.
If you were replying to @darknova, then your statement is not true.
The below shows that after is equal to before + 1:
func _ready():
var before = $SomeNode.get_child_count()
$SomeNode.add_child( new_node )
var after = $SomeNode.get_child_count()
print( before, " == ", after )
var children = self.get_children():
for existing_node in children:
var new_node = existing_node.duplicate()
new_node.rotate = PI
self.add_child( new_node )
In this case the array stored in var children is a shallow copy of the self’s actual array. So it doesn’t change while self’s original copy has children added.
I suspect that this is the case with the original for-loop, too, because it is probably get_children itself that does the shallow copy, but it is unclear from the documentation as to whether that is true.
You’re good I was dunking on my own code. I actually do it the way posted whenever I need to mess with the children during the loop, easier just to not do anything potentially weird.
My personal favorite is doing a reverse loop so I can delete items like:
for i in reverse_range(len(arr)): #reverse_range -> range(x-1, -1, -1)
if condition(arr[i]):
arr.remove_at(i)