Object
Inherited By: ARVRServer, AudioServer, CameraServer, ClassDB, EditorFileSystemDirectory, EditorNavigationMeshGenerator, EditorSelection, EditorVCSInterface, Engine, Geometry, GodotSharp, IP, Input, InputMap, JNISingleton, JSON, JSONRPC, JavaClassWrapper, JavaScript, MainLoop, Marshalls, Node, OS, Performance, Physics2DDirectBodyState, Physics2DDirectSpaceState, Physics2DServer, PhysicsDirectBodyState, PhysicsDirectSpaceState, PhysicsServer, ProjectSettings, Reference, ResourceLoader, ResourceSaver, TranslationServer, TreeItem, UndoRedo, VisualScriptEditor, VisualServer Base class for all non-built-in types.
Description
Every class which is not a built-in type inherits from this class.
Object.new() in GDScript, new Object in C#, or the “Construct Object” node in VisualScript.
free method from your script or delete the instance from C++.
Reference, which counts references and deletes itself automatically when no longer referenced. Node, another fundamental type, deletes all its children when freed from memory.
_get_property_list and handled in _get and _set. However, scripting languages and C++ have simpler means to export them.
in:
var n = Node2D.new()print("position" in n) # Prints "True".print("other_property" in n) # Prints "False".
in operator will evaluate to true as long as the key exists, even if the value is null.
_notification.
Note: Unlike references to a Reference, references to an Object stored in a variable can become invalid without warning. Therefore, it’s recommended to use Reference for data classes instead of Object.
Note: Due to a bug, you can’t create a “plain” Object using Object.new(). Instead, use ClassDB.instance("Object"). This bug only applies to Object itself, not any of its descendents like Reference.
Tutorials
- 何时以及如何避免为任何事情使用节点
advanced-exports in GDScript 导出
Methods
Signals
- script_changed ( )
Emitted whenever the object’s script is changed.
Enumerations
ConnectFlags: - CONNECT_DEFERRED = 1 —- Connects a signal in deferred mode. This way, signal emissions are stored in a queue, then set on idle time.
- CONNECT_PERSIST = 2 —- Persisting connections are saved when the object is serialized to file.
- CONNECT_ONESHOT = 4 —- One-shot connections disconnect themselves after emission.
- CONNECT_REFERENCE_COUNTED = 8 —- Connect a signal as reference-counted. This means that a given signal can be connected several times to the same target, and will only be fully disconnected once no references are left.
Constants
- NOTIFICATION_POSTINITIALIZE = 0 —- Called right when the object is initialized. Not available in script.
- NOTIFICATION_PREDELETE = 1 —- Called before the object is about to be deleted.
Method Descriptions
- Variant _get ( String property ) virtual
get.
nullif thepropertydoes not exist.
- Array _get_property_list ( ) virtual
get_property_list.
Array of dictionaries.
Dictionary must contain at least
name: Stringandtype: int(see Variant.Type) entries. Optionally, it can also includehint: int(see PropertyHint),hint_string: String, andusage: int(see PropertyUsageFlags).
- _init ( ) virtual Called when the object is initialized.
- _notification ( int what ) virtual
whatby a constant. The baseObjecthas two constants NOTIFICATION_POSTINITIALIZE and NOTIFICATION_PREDELETE, but subclasses such as Node define a lot more notifications which are also received by this method.
- bool _set ( String property, Variant value ) virtual
set.
trueif thepropertyexists.
- String _to_string ( ) virtual
to_string, and thus the object’s representation where it is converted to a string, e.g. with
print(obj). String representing the object. If not overridden, defaults to"[ClassName:RID]".
- add_user_signal ( String signal, Array arguments=[ ] )
signal. Arguments are optional, but can be added as an Array of dictionaries, each containingname: Stringandtype: int(see Variant.Type) entries.
- Variant call ( String method, … ) vararg
methodon the object and returns the result. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn’t apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).call("set", "position", Vector2(42.0, 0.0))
- call_deferred ( String method, … ) vararg
methodon the object during idle time. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:
Note: In C#, the method name must be specified as snake_case if it is defined by a built-in Godot node. This doesn’t apply to user-defined methods where you should use the same convention as in the C# source (typically PascalCase).call_deferred("set", "position", Vector2(42.0, 0.0))
- Variant callv ( String method, Array arg_array )
methodon the object and returns the result. Contrarily to call, this method does not support a variable number of arguments but expects all parameters to be via a single Array.callv("set", [ "position", Vector2(42.0, 0.0) ])
- bool can_translate_messages ( ) const
trueif the object can translate strings. See set_message_translation and tr.
- Error connect ( String signal, Object target, String method, Array binds=[ ], int flags=0 )
signalto amethodon atargetobject. Pass optionalbindsto the call as an Array of parameters. These parameters will be passed to the method after any parameter used in the call to emit_signal. Useflagsto set deferred or one-shot connections. See ConnectFlags constants.signalcan only be connected once to amethod. It will throw an error if already connected, unless the signal was connected with CONNECT_REFERENCE_COUNTED. To avoid this, first, use is_connected to check for existing connections.targetis destroyed in the game’s lifecycle, the connection will be lost. Examples:connect("pressed", self, "_on_Button_pressed") # BaseButton signalconnect("text_entered", self, "_on_LineEdit_text_entered") # LineEdit signalconnect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # User-defined signal
bindspassed to connect and parameters used when calling emit_signal:connect("hit", self, "_on_Player_hit", [ weapon_type, damage ]) # weapon_type and damage are passed lastemit_signal("hit", "Dark lord", 5) # "Dark lord" and 5 are passed firstfunc _on_Player_hit(hit_by, level, weapon_type, damage): print("Hit by %s (lvl %d) with weapon %s for %d damage" % [hit_by, level, weapon_type, damage])
- disconnect ( String signal, Object target, String method )
signalfrom amethodon the giventarget. is_connected to ensure that the connection exists.
- emit_signal ( String signal, … ) vararg
signal. The signal must exist, so it should be a built-in signal of this class or one of its parent classes, or a user-defined signal. This method supports a variable number of arguments, so parameters are passed as a comma separated list. Example:emit_signal("hit", weapon_type, damage)emit_signal("game_over")
- free ( )
Nodes, you may want to use Node.queue_free to queue the node for safe deletion at the end of the current frame.
Important: If you have a variable pointing to an object, it will not be assigned to
nullonce the object is freed. Instead, it will point to a previously freed instance and you should validate it with @GDScript.is_instance_valid before attempting to call its methods or access its properties.
- Variant get ( String property ) const
Variant value of the given
property. If thepropertydoesn’t exist, this will returnnull. Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn’t apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
- String get_class ( ) const
String. See also is_class.
Note: get_class does not take
class_namedeclarations into account. If the object has aclass_namedefined, the base class name will be returned instead.
- Array get_incoming_connections ( ) const Array of dictionaries with information about signals that are connected to the object. Dictionary contains three String entries:
sourceis a reference to the signal emitter.signal_nameis the name of the connected signal.method_nameis the name of the method to which the signal is connected.
- Variant get_indexed ( NodePath property ) const
NodePath. The node path should be relative to the current object and can use the colon character (
:) to access nested properties. Examples:"position:x"or"material:next_pass:blend_mode".
- int get_instance_id ( ) const Returns the object’s unique instance ID. EncodedObjectAsID, and can be used to retrieve the object instance with @GDScript.instance_from_id.
- Variant get_meta ( String name ) const
name.
- PoolStringArray get_meta_list ( ) const PoolStringArray.
- Array get_method_list ( ) const Array.
- Array get_property_list ( ) const
Array of dictionaries.
Dictionary contain at least
name: Stringandtype: int(see Variant.Type) entries. Optionally, it can also includehint: int(see PropertyHint),hint_string: String, andusage: int(see PropertyUsageFlags).
- Reference get_script ( ) const
Script instance, or
nullif none is assigned.
- Array get_signal_connection_list ( String signal ) const
Array of connections for the given
signal.
- Array get_signal_list ( ) const Array of dictionaries.
- bool has_meta ( String name ) const
trueif a metadata entry is found with the givenname.
- bool has_method ( String method ) const
trueif the object contains the givenmethod.
- bool has_signal ( String signal ) const
trueif the givensignalexists.
- bool has_user_signal ( String signal ) const
trueif the given user-definedsignalexists. Only signals added using add_user_signal are taken into account.
- bool is_blocking_signals ( ) const
trueif signal emission blocking is enabled.
- bool is_class ( String class ) const
trueif the object inherits from the givenclass. See also get_class. Note: is_class does not takeclass_namedeclarations into account. If the object has aclass_namedefined, is_class will returnfalsefor that name.
- bool is_connected ( String signal, Object target, String method ) const
trueif a connection exists for a givensignal,target, andmethod.
- bool is_queued_for_deletion ( ) const
trueif the Node.queue_free method was called for the object.
- notification ( int what, bool reversed=false )
_notification method of all classes that the object inherits from.
reversedistrue, _notification is called first on the object’s own class, and then up to its successive parent classes. Ifreversedisfalse, _notification is called first on the highest ancestor (Objectitself), and then down to its successive inheriting classes.
- property_list_changed_notify ( ) Notify the editor that the property list has changed, so that editor plugins can take the new values into account. Does nothing on export builds.
- remove_meta ( String name ) set_meta.
- set ( String property, Variant value )
propertydoes not exist, nothing will happen. Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn’t apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
- set_block_signals ( bool enable )
true, signal emission is blocked.
- set_deferred ( String property, Variant value )
set via call_deferred, i.e.
call_deferred("set", property, value). Note: In C#, the property name must be specified as snake_case if it is defined by a built-in Godot node. This doesn’t apply to user-defined properties where you should use the same convention as in the C# source (typically PascalCase).
- set_indexed ( NodePath property, Variant value )
NodePath. The node path should be relative to the current object and can use the colon character (
:) to access nested properties. Example:set_indexed("position", Vector2(42, 0))set_indexed("position:y", -10)print(position) # (42, -10)
- set_message_translation ( bool enable ) tr). Enabled by default.
- set_meta ( String name, Variant value )
Variant value.
remove_meta. Metadata is also removed if its value is set to
null. This means you can also useset_meta("name", null)to remove metadata for"name".
- set_script ( Reference script ) Assigns a script to the object. Each object can have a single script assigned to it, which are used to extend its functionality. _init method will be called.
- String to_string ( )
String representing the object. If not overridden, defaults to
"[ClassName:RID]". _to_string to customize the String representation.
- String tr ( String message ) const
Translates a message using translation catalogs configured in the Project Settings.
messageunchanged. See set_message_translation.
