The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

+1 vote

Hello,

I'm creating a "saving function" for saving my game state.
This function would need to use a tree in order to get the group of nodes to save. (Scene_tree.get_nodes_in_group("group_name"))

Thing is I made the Save function static to call it anywhere in my code. but I would need a tree to get all the node that need to be saved.

My question is. Is there such thing as the main tree just like the main scene?
I'm fully aware that you can have completely different tree. But I thought that there might be a "main tree" since we choose the "main scene" inside the config. And I thought that there was an easy way to access that tree since it would be the main one.

Thank you,

in Engine by (24 points)

1 Answer

+2 votes

Sorry to burst your thought bubble but there is only one tree

So the Scenetree is constructed as follows

Root > Main > Branch > Leaves
            > Branch > Leaves
            > Branch > Leaves > More leaves

And when you add Autoloads

Root > Main > Branch > Leaves
     > Autoload > Branch > Leaves

In these examples the Branches can be nodes or scene instances and the Leaves thier children, while main and autoloads can be considered stems/trunks.

To access the main node which i suspect is your intention use get_tree().get_current_scene() or if not then use get_tree().get_root() which will be the node at the very base of the Scenetree and all nodes can be accessed from it like a filesystem structure.

E.g.

get_node("/Main/Branch/Leaf")
by (6,942 points)

Your code Scene_tree.get_nodes_in_group("group_name") is already the best posible way you can impliment your save system. Ensure your nodes have a save function then call it using get_tree().call_group("group_name", "save_function") from any node

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.