Up to date
This page is up to date for Godot 4.2
.
If you still find outdated information, please open an issue.
Object¶
Inherited By: AudioServer, CameraServer, ClassDB, DisplayServer, EditorFileSystemDirectory, EditorInterface, EditorPaths, EditorSelection, EditorUndoRedoManager, EditorVCSInterface, Engine, EngineDebugger, GDExtensionManager, Geometry2D, Geometry3D, GodotSharp, Input, InputMap, IP, JavaClassWrapper, JavaScriptBridge, JNISingleton, JSONRPC, MainLoop, Marshalls, MovieWriter, NavigationMeshGenerator, NavigationServer2D, NavigationServer3D, Node, OpenXRExtensionWrapperExtension, OpenXRInteractionProfileMetadata, OS, Performance, PhysicsDirectBodyState2D, PhysicsDirectBodyState3D, PhysicsDirectSpaceState2D, PhysicsDirectSpaceState3D, PhysicsServer2D, PhysicsServer2DManager, PhysicsServer3D, PhysicsServer3DManager, PhysicsServer3DRenderingServerHandler, ProjectSettings, RefCounted, RenderingDevice, RenderingServer, ResourceLoader, ResourceSaver, ResourceUID, ScriptLanguage, TextServerManager, ThemeDB, TileData, Time, TranslationServer, TreeItem, UndoRedo, WorkerThreadPool, XRServer
Base class for all other classes in the engine.
Description¶
An advanced Variant type. All classes in the engine inherit from Object. Each class may define new properties, methods or signals, which are available to all inheriting classes. For example, a Sprite2D instance is able to call Node.add_child because it inherits from Node.
You can create new instances, using Object.new()
in GDScript, or new GodotObject
in C#.
To delete an Object instance, call free. This is necessary for most classes inheriting Object, because they do not manage memory on their own, and will otherwise cause memory leaks when no longer in use. There are a few classes that perform memory management. For example, RefCounted (and by extension Resource) deletes itself when no longer referenced, and Node deletes its children when freed.
Objects can have a Script attached to them. Once the Script is instantiated, it effectively acts as an extension to the base class, allowing it to define and inherit new properties, methods and signals.
Inside a Script, _get_property_list may be overridden to customize properties in several ways. This allows them to be available to the editor, display as lists of options, sub-divide into groups, save on disk, etc. Scripting languages offer easier ways to customize properties, such as with the @GDScript.@export annotation.
Godot is very dynamic. An object's script, and therefore its properties, methods and signals, can be changed at run-time. Because of this, there can be occasions where, for example, a property required by a method may not exist. To prevent run-time errors, see methods such as set, get, call, has_method, has_signal, etc. Note that these methods are much slower than direct references.
In GDScript, you can also check if a given property, method, or signal name exists in an object with the in
operator:
var node = Node.new()
print("name" in node) # Prints true
print("get_parent" in node) # Prints true
print("tree_entered" in node) # Prints true
print("unknown" in node) # Prints false
Notifications are int constants commonly sent and received by objects. For example, on every rendered frame, the SceneTree notifies nodes inside the tree with a Node.NOTIFICATION_PROCESS. The nodes receive it and may call Node._process to update. To make use of notifications, see notification and _notification.
Lastly, every object can also contain metadata (data about data). set_meta can be useful to store information that the object itself does not depend on. To keep your code clean, making excessive use of metadata is discouraged.
Note: Unlike references to a RefCounted, references to an object stored in a variable can become invalid without being set to null
. To check if an object has been deleted, do not compare it against null
. Instead, use @GlobalScope.is_instance_valid. It's also recommended to inherit from RefCounted for classes storing data instead of Object.
Note: The script
is not exposed like most properties. To set or get an object's Script in code, use set_script and get_script, respectively.
Tutorials¶
Methods¶
_get ( StringName property ) virtual |
|
_get_property_list ( ) virtual |
|
void |
_init ( ) virtual |
void |
_notification ( int what ) virtual |
_property_can_revert ( StringName property ) virtual |
|
_property_get_revert ( StringName property ) virtual |
|
_set ( StringName property, Variant value ) virtual |
|
_to_string ( ) virtual |
|
void |
_validate_property ( Dictionary property ) virtual |
void |
add_user_signal ( String signal, Array arguments=[] ) |
call ( StringName method, ... ) vararg |
|
call_deferred ( StringName method, ... ) vararg |
|
callv ( StringName method, Array arg_array ) |
|
can_translate_messages ( ) const |
|
void |
cancel_free ( ) |
connect ( StringName signal, Callable callable, int flags=0 ) |
|
void |
disconnect ( StringName signal, Callable callable ) |
emit_signal ( StringName signal, ... ) vararg |
|
void |
free ( ) |
get ( StringName property ) const |
|
get_class ( ) const |
|
get_incoming_connections ( ) const |
|
get_indexed ( NodePath property_path ) const |
|
get_instance_id ( ) |