SceneTree in Godot
There's not much more depth than this. This is when things start getting abstract, but don't panic.
In the last tutorial, everything revolved around the concept of nodes. A view is simply a collection of nodes. They become active as soon as they enter the visual tree.
This concept is worth going into a little more detail. The visual system is also not a core component of Godot because it is possible to skip and write a script (or C ++ code) that talks directly to the server, but creating a game in this way will do a lot of work.
This is how Godot works internally. The OS is the class, which is the only instance that runs at the beginning. Later, all drivers, servers, scripting language, visual systems, etc. are loaded.
When initialization is complete, the OS must be supplied with the main loop to run. Up to this point, all this is working interns (we can check the main / main.cpp file in the source code if we are ever interested to see how it works internally).
The game, user program, or game, starts in the main loop. Some methods for initialization in this class are passive (frame-synchronized callback), fixed (physics-synchronized callback), and input. Again, this is low-level, and while making the game in Godot, our Menloop writing rarely makes sense.
One of the way to explain how Godot works is that it is a high-level game engine on low-level middleware.
The visual system is the game engine, while the OS and server are low-level APIs.
In either case, the visual system provides its main loop to the OS, Scene Tree. It is set and set automatically while playing a scene; No additional work is required.
It is essential to know that this class exists because it has some essential uses:
When a node is part of a scene tree, the syntry singleton can be obtained only by calling Node .get_tree ().
The root viewport is at the top of the scene. Form a node, and it can be obtained in two different ways:
This node contains the main viewport, whatever is the child of a viewport is drawn inside it by default, so it would make sense that all nodes always have a node of this type at the top; Otherwise, nothing will be seen!
While other viewports are created in the scene (split-screen effects and such), this is the only one that is never created by the user. It is automatically built inside SceneTree.
While other viewports are created in the scene (for split-screen effects and such), this is the only one that is never created by the user. It is created automatically inside SceneTree.
When a node is connected indirectly or directly to the root viewport, it will become part of the scene tree.
This means that as explained in previous tutorial, it will get the _enter_tree() and _ready() callbacks (as well as _exit_tree()).
When nodes enter the view tree, they become active. They get access to everything they need from the process, input, 2D and 3D displays, notifications, play sound, groups, etc. When they are removed from the other scene tree, they lose access.
Most node operations in Godot, Like drawing 2D, processing, or getting notifications, are done in tree order. This means that parents are siblings with a smaller rank in the tree order will get notified before the current node.
"Becoming active" by entering the Scene Tree
Changing the current scene
After the scene is loaded, it is desired to change this scene for another one. The simple way to do is to use the SceneTree.change_scene() function:
This is a fast and useful way to switch scenes, but the drawback is that the game will stop until the new scene is loaded and played. At some point in your game, it can be desired to create an appropriate loading screen with progress bars, animated indicators, or thread (background) loading. This should be done automatically using autoloads (see next chapter!) And background loading.