Guide to the Godot game engine/Servers (singletons)

Servers in Godot are for low-level engine manipulation, like changing the volume of sounds, creating collision objects and more. A "Server", in this sense, is a "singleton" (meaning it is loaded/created only once, and cannot be duplicated or instanced). For the sake of simplicity, on this page, any use of the word "singleton" refers to these servers.

Nodes are just "things" that make use of singleton and present the user high-level (easier) manipulation, which can only go so far.

These are the limitations of a node-based system:
 * 1) It's slower in runtime
 * 2) Godot's source code becomes slightly more complex
 * 3) It's harder to control them in different threads
 * 4) More memory is required.

Strengths of the node system are:
 * 1) It's simpler
 * 2) It's less likely to cause bugs in your game
 * 3) It's less confusing and more attractive - it draws users is with its simplicity
 * 4) It's faster to set up Node trees than call each singleton's functions for everything

Whether you use high-level, low-level or a combination of both is completely up to you and the game you are making.

Some games simply need the functionality of a singleton since nodes just don't offer the functionality you need, or making that functionality with nodes would be too difficult, time consuming, computationally expensive, or all three of those things.

Many server functions return or use RIDs (Resource ID). They must be kept stored in a variable to remain modifiable. In the case of Resource types, like textures, you must store the resource as a variable as well, or both it and its corresponding RID will be erased.

For more information on usage, see the docs.

VisualServer
NOTE: Godot's API for everything visual will change in Godot 4

The VisualServer creates a 2D "canvas" and a 3D "scenario", which can be given objects, both 2D and 3D, to draw. They will not draw unless you use a Viewport node.

Use  to add an item to the main canvas. You can create a canvas to use its RID with. You can attach a canvas to a Viewport with, providing it is not already attached to one.

For 3D, use  for a new scenario,   for the existing scenario and   for adding an object/light to a scenario.

CanvasItems and VisualInstance nodes contain methods that allow drawing directly. In 2D, you can draw circles and rectangles, as well as textures and text. Using VisualInstance, you can draw meshes into 3D.

Helpful simple methods:

.(left, top, right, bottom) .

.()

Example of drawing a texture with 25 width and height:

texture = :   sprite =. .(, texture.) .(sprite, )

AudioServer
The AudioServer is used for low-level audio access. It can also record and playback recorded audio. This is useful when implementing voice-chat in games.

The AudioServer does not use RIDs.

PhysicsServer
The server for 3D physics.

Physics servers are for creating areas and bodies, but do not place them on the scene tree.

The below code creates a wall that is 5 units high, half a unit thick, and 4 units wide and adds it the the physics space.

shape = .(.SHAPE_BOX) .(shape, ) .(body, shape) .(body, .space)

Physics2DServer
The 2D version of PhysicsServer. It is used in exactly the same way, but some values may need to be adjusted, like Vector3s to Vector2s.

ARVRServer
The ARVRServer, or the XRServer, is the heart of Godot's advanced XR solution, and handles all the processing.

See also: XR Godot tutorials.

CameraServer
The CameraServer is not used to keep track of Camera nodes like it sounds. It is a server to use external cameras. Like the camera at the back of your phone. It can take pictures, but is mostly used in AR.

This server doesn't use RIDs.