Struct SceneTree
Manages the game loop via a hierarchy of nodes.
struct SceneTree
;
As one of the most important classes, the SceneTree
manages the hierarchy of nodes in a scene as well as scenes themselves. Nodes can be added, retrieved and removed. The whole scene tree (and thus the current scene) can be paused. Scenes can be loaded, switched and reloaded.
You can also use the SceneTree
to organize your nodes into groups: every node can be assigned as many groups as you want to create, e.g. a "enemy" group. You can then iterate these groups or even call methods and set properties on all the group's members at once.
SceneTree
is the default MainLoop
implementation used by scenes, and is thus in charge of the game loop.
Properties
Name | Type | Description |
---|---|---|
currentScene [get, set]
|
Node | The current scene. |
debugCollisionsHint [get, set]
|
bool | If true , collision shapes will be visible when running the game from the editor for debugging purposes.
|
debugNavigationHint [get, set]
|
bool | If true , navigation polygons will be visible when running the game from the editor for debugging purposes.
|
editedSceneRoot [get, set]
|
Node | The root of the edited scene. |
multiplayer [get, set]
|
MultiplayerAPI | The default MultiplayerAPI instance for this SceneTree .
|
multiplayerPoll [get, set]
|
bool | If true (default value), enables automatic polling of the MultiplayerAPI for this SceneTree during idleFrame .
If false , you need to manually call MultiplayerAPI to process network packets and deliver RPCs/RSETs. This allows running RPCs/RSETs in a different loop (e.g. physics, thread, specific time step) and for manual Mutex protection when accessing the MultiplayerAPI from threads.
|
networkPeer [get, set]
|
NetworkedMultiplayerPeer | The peer object to handle the RPC system (effectively enabling networking when set). Depending on the peer itself, the SceneTree will become a network server (check with isNetworkServer ) and will set the root node's network mode to master, or it will become a regular peer with the root node set to puppet. All child nodes are set to inherit the network mode by default. Handling of networking-related events (connection, disconnection, new clients) is done by connecting to SceneTree 's signals.
|
paused [get, set]
|
bool | If true , the SceneTree is paused. Doing so will have the following behavior:
- 2D and 3D physics will be stopped.
- Node , Node and Node will not be called anymore in nodes.
|
refuseNewNetworkConnections [get, set]
|
bool | If true , the SceneTree 's networkPeer refuses new incoming connections.
|
root [get]
|
Viewport | The SceneTree 's root Viewport .
|
useFontOversampling [get, set]
|
bool | If true , font oversampling is used.
|
Methods
Name | Description |
---|---|
_changeScene
|
|
_connectedToServer
|
|
_connectionFailed
|
|
_networkPeerConnected
|
|
_networkPeerDisconnected
|
|
_serverDisconnected
|
|
callGroup
|
Calls method on each member of the given group.
|
callGroupFlags
|
Calls method on each member of the given group, respecting the given groupcallflags .
|
changeScene
|
Changes the running scene to the one at the given path , after loading it into a PackedScene and creating a new instance.
Returns constant OK on success, constant ERR_CANT_OPEN if the path cannot be loaded into a PackedScene , or constant ERR_CANT_CREATE if that scene cannot be instantiated.
|
changeSceneTo
|
Changes the running scene to a new instance of the given PackedScene .
Returns constant OK on success or constant ERR_CANT_CREATE if the scene cannot be instantiated.
|
createTimer
|
Returns a SceneTreeTimer which will SceneTreeTimer after the given time in seconds elapsed in this SceneTree . If pause_mode_process is set to false , pausing the SceneTree will also pause the timer.
Commonly used to create a one-shot delay timer as in the following example:
|
getCurrentScene
|
|
getEditedSceneRoot
|
|
getFrame
|
Returns the current frame number, i.e. the total frame count since the application started. |
getMultiplayer
|
|
getNetworkConnectedPeers
|
Returns the peer IDs of all connected peers of this SceneTree 's networkPeer .
|
getNetworkPeer
|
|
getNetworkUniqueId
|
Returns the unique peer ID of this SceneTree 's networkPeer .
|
getNodeCount
|
Returns the number of nodes in this SceneTree .
|
getNodesInGroup
|
Returns a list of all nodes assigned to the given group. |
getRoot
|
|
getRpcSenderId
|
Returns the sender's peer ID for the most recently received RPC call. |
hasGroup
|
Returns true if the given group exists.
|
hasNetworkPeer
|
Returns true if there is a networkPeer set.
|
isDebuggingCollisionsHint
|
|
isDebuggingNavigationHint
|
|
isInputHandled
|
Returns true if the most recent InputEvent was marked as handled with setInputAsHandled .
|
isMultiplayerPollEnabled
|
|
isNetworkServer
|
Returns true if this SceneTree 's networkPeer is in server mode (listening for connections).
|
isPaused
|
|
isRefusingNewNetworkConnections
|
|
isUsingFontOversampling
|
|
notifyGroup
|
Sends the given notification to all members of the group .
|
notifyGroupFlags
|
Sends the given notification to all members of the group , respecting the given groupcallflags .
|
queueDelete
|
Queues the given object for deletion, delaying the call to GodotObject to after the current frame.
|
quit
|
Quits the application. A process exit_code can optionally be passed as an argument. If this argument is 0 or greater, it will override the OS defined before quitting the application.
|
reloadCurrentScene
|
Reloads the currently active scene.
Returns constant OK on success, constant ERR_UNCONFIGURED if no currentScene was defined yet, constant ERR_CANT_OPEN if currentScene cannot be loaded into a PackedScene , or constant ERR_CANT_CREATE if the scene cannot be instantiated.
|
setAutoAcceptQuit
|
If true , the application automatically accepts quitting. Enabled by default.
For mobile platforms, see setQuitOnGoBack .
|
setCurrentScene
|
|
setDebugCollisionsHint
|
|
setDebugNavigationHint
|
|
setEditedSceneRoot
|
|
setGroup
|
Sets the given property to value on all members of the given group.
|
setGroupFlags
|
Sets the given property to value on all members of the given group, respecting the given groupcallflags .
|
setInputAsHandled
|
Marks the most recent InputEvent as handled.
|
setMultiplayer
|
|
setMultiplayerPollEnabled
|
|
setNetworkPeer
|
|
setPause
|
|
setQuitOnGoBack
|
If true , the application quits automatically on going back (e.g. on Android). Enabled by default.
To handle 'Go Back' button when this option is disabled, use constant MainLoop .
|
setRefuseNewNetworkConnections
|
|
setScreenStretch
|
Configures screen stretching to the given stretchmode , stretchaspect , minimum size and shrink ratio.
|
setUseFontOversampling
|
Enums
Name | Description |
---|---|
Constants
|
|
GroupCallFlags
|
|
StretchAspect
|
|
StretchMode
|