Godot Version
4.4
Question
I am writing code that includes a static function, inside this as part of the setup I need to remove all the children of a node;
# 'player.action_bar' is a UI element showing turn details, as this is for a turn-based game
player.action_bar.get_children().map(func(node : Node) -> Node: node.free(); return node)
After this I want to then repopulate the action bar with the new data;
for combatant : Node in combatants:
player.action_bar.add_child(action_bar_item.instantiate())
#... more code
But this can fail since it is adding them before the last ones are gone, causing certain names to have numbers added to the end, which isn’t ideal since other parts of code rely on the specific name of the nodes.
So I try to await a frame to give the nodes time to free, but I can’t since to do the standard ‘await get_tree.process_frame’ relies on get_tree(), which isn’t static so I can’t.
So I try creating a timer variable using Timer.new(), but trying to call ‘start()’ fails as it isn’t added to the scene tree, and I can’t add it to the scene tree since ‘self’ and ‘add_child()’ aren’t static.
Is it possible to await either a frame or a sub-second amount of time inside a static function? Or will I have to make this a singleton and un-static everything?
Thanks.