Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

Object

被繼承: AccessibilityServer, AudioServer, CameraServer, ClassDB, DisplayServer, EditorFileSystemDirectory, EditorInterface, EditorPaths, EditorSelection, EditorUndoRedoManager, EditorVCSInterface, Engine, EngineDebugger, FramebufferCacheRD, GDExtensionManager, Geometry2D, Geometry3D, GodotInstance, Input, InputMap, IP, JavaClassWrapper, JavaScriptBridge, JNISingleton, JSONRPC, MainLoop, Marshalls, MovieWriter, NativeMenu, NavigationMeshGenerator, NavigationServer2D, NavigationServer2DManager, NavigationServer3D, NavigationServer3DManager, Node, OpenXRExtensionWrapper, OpenXRInteractionProfileMetadata, OS, Performance, PhysicsDirectBodyState2D, PhysicsDirectBodyState3D, PhysicsDirectSpaceState2D, PhysicsDirectSpaceState3D, PhysicsServer2D, PhysicsServer2DManager, PhysicsServer3D, PhysicsServer3DManager, PhysicsServer3DRenderingServerHandler, ProjectSettings, RefCounted, RenderData, RenderingDevice, RenderingServer, RenderSceneData, ResourceLoader, ResourceSaver, ResourceUID, ScriptLanguage, ShaderIncludeDB, TextServerManager, ThemeDB, TileData, Time, TranslationServer, TreeItem, UndoRedo, UniformSetCacheRD, WorkerThreadPool, XRServer, XRVRS

引擎中所有其他類的基底類別。

說明

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.

Note: In a boolean context, an Object will evaluate to false if it is equal to null or it has been freed. Otherwise, an Object will always evaluate to true. See also @GlobalScope.is_instance_valid().

教學

方法

Variant

_get(property: StringName) virtual

Array[Dictionary]

_get_property_list() virtual

void

_init() virtual

Variant

_iter_get(iter: Variant) virtual

bool

_iter_init(iter: Array) virtual

bool

_iter_next(iter: Array) virtual

void

_notification(what: int) virtual

bool

_property_can_revert(property: StringName) virtual

Variant

_property_get_revert(property: StringName) virtual

bool

_set(property: StringName, value: Variant) virtual

String

_to_string() virtual

void

_validate_property(property: Dictionary) virtual

void

add_user_signal(signal: String, arguments: Array = [])

Variant

call(method: StringName, ...) vararg

Variant

call_deferred(method: StringName, ...) vararg

Variant

callv(method: StringName, arg_array: Array)

bool

can_translate_messages() const

void

cancel_free()

Error

connect(signal: StringName, callable: Callable, flags: int = 0)

void

disconnect(signal: StringName, callable: Callable)

Error

emit_signal(signal: StringName, ...) vararg

void

free()

Variant

get(property: StringName) const

String

get_class() const

Array[Dictionary]

get_incoming_connections() const

Variant

get_indexed(property_path: NodePath) const

int

get_instance_id() const

Variant

get_meta(name: StringName, default: Variant = null) const

Array[StringName]

get_meta_list() const

int

get_method_argument_count(method: StringName) const

Array[Dictionary]

get_method_list() const

Array[Dictionary]

get_property_list() const

Variant

get_script() const

Array[Dictionary]

get_signal_connection_list(signal: StringName) const

Array[Dictionary]

get_signal_list() const

StringName

get_translation_domain() const

bool

has_connections(signal: StringName) const

bool

has_meta(name: StringName) const

bool

has_method(method: StringName) const

bool

has_signal(signal: StringName) const

bool

has_user_signal(signal: StringName) const

bool

is_blocking_signals() const

bool

is_class(class: StringName) const

bool

is_connected(signal: StringName, callable: Callable) const

bool

is_queued_for_deletion() const

void

notification(what: int, reversed: bool = false)

void

notify_property_list_changed()

bool

property_can_revert(property: StringName) const

Variant

property_get_revert(property: StringName) const

void

remove_meta(name: StringName)

void

remove_user_signal(signal: StringName)

void

set(property: StringName, value: Variant)

void

set_block_signals(enable: bool)

void

set_deferred(property: StringName, value: Variant)

void

set_indexed(property_path: NodePath, value: Variant)

void

set_message_translation(enable: bool)

void

set_meta(name: StringName, value: Variant)

void

set_script(script: Variant)

void

set_translation_domain(domain: StringName)

String

to_string()

String

tr(message: StringName, context: StringName = &"") const

String

tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") const


訊號

property_list_changed() 🔗

呼叫 notify_property_list_changed() 時發出。


script_changed() 🔗

該物件的腳本發生改變時發出。

注意:發出這個訊號時,新腳本還沒有初始化。如果你需要存取新腳本,請用 CONNECT_DEFERRED 推遲與這個訊號的連接。


列舉

flags ConnectFlags: 🔗

ConnectFlags CONNECT_DEFERRED = 1

延遲連接會在空閒時觸發 Callable(目前影格的末尾),不會立即觸發。

ConnectFlags CONNECT_PERSIST = 2

Persisting connections are stored when the object is serialized (such as when using PackedScene.pack()). In the editor, connections created through the Signals dock are always persisting.

Note: Connections to lambda functions (that is, when the function code is embedded in the connect() call) cannot be made persistent.

ConnectFlags CONNECT_ONE_SHOT = 4

一次性連接,會在觸發後自行斷開。

ConnectFlags CONNECT_REFERENCE_COUNTED = 8

引用計數連接可以多次分配給同一個 Callable。每斷開一次連接會讓內部計數器減一。訊號會在計數器變為 0 時完全斷開連接。

ConnectFlags CONNECT_APPEND_SOURCE_OBJECT = 16

On signal emission, the source object is automatically appended after the original arguments of the signal, regardless of the connected Callable's unbinds which affect only the original arguments of the signal (see Callable.unbind(), Callable.get_unbound_arguments_count()).

extends Object

signal test_signal

func test():
    print(self) # Prints e.g. <Object#35332818393>
    test_signal.connect(prints.unbind(1), CONNECT_APPEND_SOURCE_OBJECT)
    test_signal.emit("emit_arg_1", "emit_arg_2") # Prints emit_arg_1 <Object#35332818393>

常數

NOTIFICATION_POSTINITIALIZE = 0 🔗

該物件初始化時收到的通知,發生在附加腳本之前。內部使用。

NOTIFICATION_PREDELETE = 1 🔗

Notification received when the object is about to be deleted. Can be used like destructors in object-oriented programming languages.

This notification is sent in reversed order.

NOTIFICATION_EXTENSION_RELOADED = 2 🔗

Notification received when the object finishes hot reloading. This notification is only sent for extensions classes and derived.


方法說明

Variant _get(property: StringName) virtual 🔗

Override this method to customize the behavior of get(). Should return the given property's value, or null if the property should be handled normally.

Combined with _set() and _get_property_list(), this method allows defining custom properties, which is particularly useful for editor plugins.

Note: This method is not called when getting built-in properties of an object, including properties defined with @GDScript.@export.

func _get(property):
    if property == "fake_property":
        print("Getting my property!")
        return 4
    return null

func _get_property_list():
    return [
        { "name": "fake_property", "type": TYPE_INT }
    ]

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns a non-null value.

Warning: This method must be thread-safe if overridden. Otherwise, the engine may crash when trying to save a resource containing the object.


Array[Dictionary] _get_property_list() virtual 🔗

Override this method to provide a custom list of additional properties to handle by the engine.

Should return a property list, as an Array of dictionaries. The result is added to the array of get_property_list(), and should be formatted in the same way. Each Dictionary must at least contain the name and type entries.

You can use _property_can_revert() and _property_get_revert() to customize the default values of the properties added by this method.

The example below displays a list of numbers shown as words going from ZERO to FIVE, with number_count controlling the size of the list:

@tool
extends Node

@export var number_count = 3:
    set(nc):
        number_count = nc
        numbers.resize(number_count)
        notify_property_list_changed()

var numbers = PackedInt32Array([0, 0, 0])

func _get_property_list():
    var properties: Array[Dictionary] = []

    for i in range(number_count):
        properties.append({
            "name": "number_%d" % i,
            "type": TYPE_INT,
            "hint": PROPERTY_HINT_ENUM,
            "hint_string": "ZERO,ONE,TWO,THREE,FOUR,FIVE",
        })

    return properties

func _get(property):
    if property.begins_with("number_"):
        var index = property.get_slice("_", 1).to_int()
        return numbers[index]
    return null

func _set(property, value):
    if property.begins_with("number_"):
        var index = property.get_slice("_", 1).to_int()
        numbers[index] = value
        return true
    return false

Note: This method is intended for advanced purposes. For most common use cases, the scripting languages offer easier ways to handle properties. See @GDScript.@export, @GDScript.@export_enum, @GDScript.@export_group, etc. If you want to customize exported properties, use _validate_property().

Note: If the object's script is not @GDScript.@tool, this method will not be called in the editor.

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy.

Warning: This method must be thread-safe if overridden. Otherwise, the engine may crash when trying to save a resource containing the object.


void _init() virtual 🔗

Called when the object's script is instantiated, oftentimes after the object is initialized in memory (through Object.new() in GDScript, or new GodotObject in C#). It can be also defined to take in parameters. This method is similar to a constructor in most programming languages.

Note: If _init() is defined with required parameters, the Object with script may only be created directly. If any other means (such as PackedScene.instantiate() or Node.duplicate()) are used, the script's initialization will fail.


Variant _iter_get(iter: Variant) virtual 🔗

Returns the current iterable value. iter stores the iteration state, but unlike _iter_init() and _iter_next() the state is supposed to be read-only, so there is no Array wrapper.

Tip: In GDScript, you can use a subtype of Variant as the return type for _iter_get(). The specified type will be used to set the type of the iterator variable in for loops, enhancing type safety.


bool _iter_init(iter: Array) virtual 🔗

Initializes the iterator. iter stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns true so long as the iterator has not reached the end.

class MyRange:
    var _from
    var _to

    func _init(from, to):
        assert(from <= to)
        _from = from
        _to = to

    func _iter_init(iter):
        iter[0] = _from
        return iter[0] < _to

    func _iter_next(iter):
        iter[0] += 1
        return iter[0] < _to

    func _iter_get(iter):
        return iter

func _ready():
    var my_range = MyRange.new(2, 5)
    for x in my_range:
        print(x) # Prints 2, 3, 4.

Note: Avoid storing iterator state in a member variable, use the iter parameter instead. Otherwise, you won't be able to reuse the same iterator instance in nested loops.

See also online docs.


bool _iter_next(iter: Array) virtual 🔗

Moves the iterator to the next iteration. iter stores the iteration state. Since GDScript does not support passing arguments by reference, a single-element array is used as a wrapper. Returns true so long as the iterator has not reached the end.


void _notification(what: int) virtual 🔗

Called when the object receives a notification, which can be identified in what by comparing it with a constant. See also notification().

func _notification(what):
    if what == NOTIFICATION_PREDELETE:
        print("Goodbye!")

Note: The base Object defines a few notifications (NOTIFICATION_POSTINITIALIZE and NOTIFICATION_PREDELETE). Inheriting classes such as Node define a lot more notifications, which are also received by this method.

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. Call order depends on the reversed argument of notification() and varies between different notifications. Most notifications are sent in the forward order (i.e. Object class first, most derived class last).


bool _property_can_revert(property: StringName) virtual 🔗

Override this method to customize the given property's revert behavior. Should return true if the property has a custom default value and is revertible in the Inspector dock. Use _property_get_revert() to specify the property's default value.

Note: This method must return consistently, regardless of the current value of the property.

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns true.


Variant _property_get_revert(property: StringName) virtual 🔗

Override this method to customize the given property's revert behavior. Should return the default value for the property. If the default value differs from the property's current value, a revert icon is displayed in the Inspector dock.

Note: _property_can_revert() must also be overridden for this method to be called.

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns a non-null value.


bool _set(property: StringName, value: Variant) virtual 🔗

Override this method to customize the behavior of set(). Should set the property to value and return true, or false if the property should be handled normally. The exact way to set the property is up to this method's implementation.

Combined with _get() and _get_property_list(), this method allows defining custom properties, which is particularly useful for editor plugins.

Note: This method is not called when setting built-in properties of an object, including properties defined with @GDScript.@export.

var internal_data = {}

func _set(property, value):
    if property == "fake_property":
        # Storing the value in the fake property.
        internal_data["fake_property"] = value
        return true
    return false

func _get_property_list():
    return [
        { "name": "fake_property", "type": TYPE_INT }
    ]

Note: Unlike other virtual methods, this method is called automatically for every script that overrides it. This means that the base implementation should not be called via super in GDScript or its equivalents in other languages. The bottom-most sub-class will be called first, with subsequent calls ascending the class hierarchy. The call chain will stop on the first class that returns true.


String _to_string() virtual 🔗

Override this method to customize the return value of to_string(), and therefore the object's representation as a String.

func _to_string():
    return "Welcome to Godot 4!"

func _init():
    print(self)       # Prints "Welcome to Godot 4!"
    var a = str(self) # a is "Welcome to Godot 4!"

void _validate_property(property: Dictionary) virtual 🔗

Override this method to customize existing properties. Every property info goes through this method, except properties added with _get_property_list(). The dictionary contents is the same as in _get_property_list().

@tool
extends Node

@export var is_number_editable: bool:
    set(value):
        is_number_editable = value
        notify_property_list_changed()
@export var number: int

func _validate_property(property: Dictionary):
    if property.name == "number" and not is_number_editable:
        property.usage |= PROPERTY_USAGE_READ_ONLY

void add_user_signal(signal: String, arguments: Array = []) 🔗

Adds a user-defined signal named signal. Optional arguments for the signal can be added as an Array of dictionaries, each defining a name String and a type int (see Variant.Type). See also has_user_signal() and remove_user_signal().

add_user_signal("hurt", [
    { "name": "damage", "type": TYPE_INT },
    { "name": "source", "type": TYPE_OBJECT }
])

Variant call(method: StringName, ...) vararg 🔗

在對象上呼叫 method 並返回結果。該方法支援可變數量的參數,因此參數可以作為逗號分隔的列表傳遞。

var node = Node3D.new()
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)

注意:在 C# 中,在引用 Godot 內建方法時,method 必須為 snake_case 格式。最好使用 MethodName 類中公開的名稱,以避免在每次呼叫時分配新的 StringName


Variant call_deferred(method: StringName, ...) vararg 🔗

Calls the method on the object during idle time. Always returns null, not the method's result.

Idle time happens mainly at the end of process and physics frames. In it, deferred calls will be run until there are none left, which means you can defer calls from other deferred calls and they'll still be run in the current idle time cycle. This means you should not call a method deferred from itself (or from a method called by it), as this causes infinite recursion the same way as if you had called the method directly.

This method supports a variable number of arguments, so parameters can be passed as a comma separated list.

var node = Node3D.new()
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)

For methods that are deferred from the same thread, the order of execution at idle time is identical to the order in which call_deferred was called.

See also Callable.call_deferred().

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.

Note: If you're looking to delay the function call by a frame, refer to the SceneTree.process_frame and SceneTree.physics_frame signals.

var node = Node3D.new()
# Make a Callable and bind the arguments to the node's rotate() call.
var callable = node.rotate.bind(Vector3(1.0, 0.0, 0.0), 1.571)
# Connect the callable to the process_frame signal, so it gets called in the next process frame.
# CONNECT_ONE_SHOT makes sure it only gets called once instead of every frame.
get_tree().process_frame.connect(callable, CONNECT_ONE_SHOT)

Variant callv(method: StringName, arg_array: Array) 🔗

Calls the method on the object and returns the result. Unlike call(), this method expects all parameters to be contained inside arg_array.

var node = Node3D.new()
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.


bool can_translate_messages() const 🔗

如果允許該物件使用 tr()tr_n() 翻譯消息,則返回 true。另見 set_message_translation()


void cancel_free() 🔗

如果在 NOTIFICATION_PREDELETE 時呼叫該方法,則該物件拒絕釋放,仍會保持已分配的狀態。主要是作為內建函式使用,用於錯誤處理,避免使用者釋放不想釋放的對象。


Error connect(signal: StringName, callable: Callable, flags: int = 0) 🔗

Connects a signal by name to a callable. Optional flags can be also added to configure the connection's behavior (see ConnectFlags constants).

A signal can only be connected once to the same Callable. If the signal is already connected, this method returns @GlobalScope.ERR_INVALID_PARAMETER and generates an error, unless the signal is connected with CONNECT_REFERENCE_COUNTED. To prevent this, use is_connected() first to check for existing connections.

Note: If the callable's object is freed, the connection will be lost.

Note: In GDScript, it is generally recommended to connect signals with Signal.connect() instead.

Note: This method, and all other signal-related methods, are thread-safe.


void disconnect(signal: StringName, callable: Callable) 🔗

按名稱從給定的 callable 斷開 signal。如果連接不存在,則生成一個錯誤。使用 is_connected() 確保該連接存在。


Error emit_signal(signal: StringName, ...) vararg 🔗

按名稱發出給定的 signal。該訊號必須存在,所以它應該是該類或其繼承類之一的內建訊號,或者是使用者定義的訊號(參見 add_user_signal())。該方法支持可變數量的參數,所以參數可以以逗號分隔的列表形式傳遞。

如果 signal 不存在或參數無效,則返回 @GlobalScope.ERR_UNAVAILABLE

emit_signal("hit", "劍", 100)
emit_signal("game_over")

注意:在C#中,在引用內建 Godot 訊號時,signal 必須是 snake_case。最好使用 SignalName 類中公開的名稱,以避免在每次呼叫時分配一個新的 StringName


void free() 🔗

Deletes the object from memory. Pre-existing references to the object become invalid, and any attempt to access them will result in a runtime error. Checking the references with @GlobalScope.is_instance_valid() will return false. This is equivalent to the memdelete function in GDExtension C++.


Variant get(property: StringName) const 🔗

Returns the Variant value of the given property. If the property does not exist, this method returns null.

var node = Node2D.new()
node.rotation = 1.5
var a = node.get("rotation") # a is 1.5

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


String get_class() const 🔗

返回該物件的內建類別名稱,作為一個 String。另請參閱 is_class()

注意:該方法將忽略 class_name 宣告。如果該物件的腳本定義了一個 class_name,則改為返回內建基底類別別名稱稱。


Array[Dictionary] get_incoming_connections() const 🔗

返回該物件接收到的訊號連接的 Array。每個連接都被表示為包含三個條目的 Dictionary


Variant get_indexed(property_path: NodePath) const 🔗

獲取該物件的某個屬性,該屬性的屬性路徑由 property_path 給出。該路徑應該是相對於目前物件的 NodePath,可是使用英文冒號(:)存取內嵌屬性。

範例:"position:x""material:next_pass:blend_mode"

var node = Node2D.new()
node.position = Vector2(5, -10)
var a = node.get_indexed("position")   # a 為 Vector2(5, -10)
var b = node.get_indexed("position:y") # b 為 -10

注意:在 C# 中引用內建 Godot 屬性時 property_path 必須為 snake_case 蛇形大小寫。請優先使用 PropertyName 類中暴露的名稱,避免每次呼叫都重新分配一個 StringName

注意:這個方法不支援指向 SceneTree 中節點的路徑,僅支援子屬性路徑。在節點語境下,請改用 Node.get_node_and_resource()


int get_instance_id() const 🔗

Returns the object's unique instance ID. This ID can be saved in EncodedObjectAsID, and can be used to retrieve this object instance with @GlobalScope.instance_from_id().

Note: This ID is only useful during the current session. It won't correspond to a similar object if the ID is sent over a network, or loaded from a file at a later time.


Variant get_meta(name: StringName, default: Variant = null) const 🔗

返回該對象的中繼資料中名稱為 name 的條目。如果不存在該條目,則返回 default。如果 defaultnull,則還會生成錯誤。

注意:中繼資料的名稱必須是符合 StringName.is_valid_identifier() 的有效識別字。

注意:名稱以底線(_)開頭的中繼資料僅供編輯器使用。僅供編輯器使用的中繼資料不會在“屬性檢視器”中顯示,雖然仍然能夠被這個方法找到,但是不應該進行編輯。


Array[StringName] get_meta_list() const 🔗

Returns the object's metadata entry names as an Array of StringNames.


int get_method_argument_count(method: StringName) const 🔗

Returns the number of arguments of the given method by name.

Note: In C#, method must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the MethodName class to avoid allocating a new StringName on each call.


Array[Dictionary] get_method_list() const 🔗

將該物件的方法及對應簽章作為字典 Array 返回。每個 Dictionary 包含以下條目:

-name 是該方法的名稱,為 String

-args 是代表參數的字典 Array

-default_args 是預設參數,為變體 Array

-flagsMethodFlags 的組合;

-id 是該方法的內部識別字 int

-return 是返回值,為 Dictionary

注意:argsreturn 的字典格式與 get_property_list() 的結果相同,但不會用到所有條目。


Array[Dictionary] get_property_list() const 🔗

以字典 Array 的形式返回該物件的屬性列表。每個 Dictionary 中都包含如下條目:


Variant get_script() const 🔗

返回該物件的 Script 實例,如果沒有附加腳本,則返回 null


Array[Dictionary] get_signal_connection_list(signal: StringName) const 🔗

Returns an Array of connections for the given signal name. Each connection is represented as a Dictionary that contains three entries:


Array[Dictionary] get_signal_list() const 🔗

Returns the list of existing signals as an Array of dictionaries.

Note: Due to the implementation, each Dictionary is formatted very similarly to the returned values of get_method_list().


StringName get_translation_domain() const 🔗

Returns the name of the translation domain used by tr() and tr_n(). See also TranslationServer.


bool has_connections(signal: StringName) const 🔗

Returns true if any connection exists on the given signal name.

Note: In C#, signal must be in snake_case when referring to built-in Godot methods. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


bool has_meta(name: StringName) const 🔗

如果找到名稱為 name 的中繼資料條目,則返回 true。另請參閱 get_meta()set_meta()remove_meta()

注意:中繼資料的名稱 name 必須是符合 StringName.is_valid_identifier() 的有效識別字。

注意:名稱 name 以底線(_)開頭的中繼資料僅供編輯器使用。僅供編輯器使用的中繼資料不會在“屬性檢視器”中顯示,雖然仍然能夠被這個方法找到,但是不應該進行編輯。


bool has_method(method: StringName) const 🔗

如果該物件中存在給定的方法名 method,則返回 true

注意:在 C# 中引用內建 Godot 方法時 method 必須為 snake_case 蛇形大小寫。請優先使用 MethodName 類中暴露的名稱,避免每次呼叫都重新分配一個 StringName


bool has_signal(signal: StringName) const 🔗

Returns true if the given signal name exists in the object.

Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


bool has_user_signal(signal: StringName) const 🔗

Returns true if the given user-defined signal name exists. Only signals added with add_user_signal() are included. See also remove_user_signal().


bool is_blocking_signals() const 🔗

如果該物件正在阻止發出訊號,則返回 true。見 set_block_signals()


bool is_class(class: StringName) const 🔗

如果該物件繼承自給定的 class 則返回 true。另見 get_class()

var sprite2d = Sprite2D.new()
sprite2d.is_class("Sprite2D") # 返回 true
sprite2d.is_class("Node")     # 返回 true
sprite2d.is_class("Node3D")   # 返回 false

注意:此方法忽略物件腳本中的 class_name 宣告。


bool is_connected(signal: StringName, callable: Callable) const 🔗

Returns true if a connection exists between the given signal name and callable.

Note: In C#, signal must be in snake_case when referring to built-in Godot signals. Prefer using the names exposed in the SignalName class to avoid allocating a new StringName on each call.


bool is_queued_for_deletion() const 🔗

Returns true if the methods Node.queue_free() or SceneTree.queue_delete() was called for the object.

Note: This method does not return true on children of the node that Node.queue_free() has been called on, even though they will be freed together with the parent.


void notification(what: int, reversed: bool = false) 🔗

將給定的 what 通知發送給物件繼承的所有類,觸發對 _notification() 的呼叫,從最高祖先(Object 類)開始,向下一直到物件的腳本。

如果 reversedtrue,則呼叫順序會被顛倒。

var player = Node2D.new()
player.set_script(load("res://player.gd"))

player.notification(NOTIFICATION_ENTER_TREE)
# 呼叫順序是 Object -> Node -> Node2D -> player.gd。

player.notification(NOTIFICATION_ENTER_TREE, true)
# 呼叫順序是 player.gd -> Node2D -> Node -> Object。

void notify_property_list_changed() 🔗

發出 property_list_changed 訊號。這主要是用來更新編輯器,以讓屬性檢視器和編輯器外掛程式被正確更新。


bool property_can_revert(property: StringName) const 🔗

如果給定的屬性 property 有自訂的預設值,則返回 true。請使用 property_get_revert() 獲取 property 的預設值。

注意:“屬性檢視器”面板會使用這個方法來顯示恢復圖示。該物件必須實作 _property_can_revert() 來自訂預設值。如果未實作 _property_can_revert(),則這個方法返回 false


Variant property_get_revert(property: StringName) const 🔗

返回給定的屬性 property 的自訂預設值。請使用 property_can_revert() 檢查 property 是否有自訂的預設值。

注意:“屬性檢視器”面板會使用這個方法來顯示恢復圖示。該物件必須實作 _property_get_revert() 來自訂預設值。如果未實作 _property_get_revert(),則這個方法返回 null


void remove_meta(name: StringName) 🔗

從對象的中繼資料中移除名稱為 name 的條目。另請參閱 has_meta()get_meta()、和 set_meta()

注意:中繼資料的名稱 name 必須是符合 StringName.is_valid_identifier() 的有效識別字。

注意:名稱 name 以底線(_)開頭的中繼資料僅供編輯器使用。僅供編輯器使用的中繼資料不會在“屬性檢視器”中顯示,雖然仍然能夠被這個方法找到,但是不應該進行編輯。


void remove_user_signal(signal: StringName) 🔗

Removes the given user signal signal from the object. See also add_user_signal() and has_user_signal().


void set(property: StringName, value: Variant) 🔗

Assigns value to the given property. If the property does not exist or the given value's type doesn't match, nothing happens.

var node = Node2D.new()
node.set("global_scale", Vector2(8, 2.5))
print(node.global_scale) # Prints (8.0, 2.5)

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_block_signals(enable: bool) 🔗

如果設定為 true,這該物件將無法發出訊號。因此,emit_signal() 和訊號連接將不起作用,直到該屬性被設定為 false


void set_deferred(property: StringName, value: Variant) 🔗

Assigns value to the given property, at the end of the current frame. This is equivalent to calling set() through call_deferred().

var node = Node2D.new()
add_child(node)

node.rotation = 1.5
node.set_deferred("rotation", 3.0)
print(node.rotation) # Prints 1.5

await get_tree().process_frame
print(node.rotation) # Prints 3.0

Note: In C#, property must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_indexed(property_path: NodePath, value: Variant) 🔗

Assigns a new value to the property identified by the property_path. The path should be a NodePath relative to this object, and can use the colon character (:) to access nested properties.

var node = Node2D.new()
node.set_indexed("position", Vector2(42, 0))
node.set_indexed("position:y", -10)
print(node.position) # Prints (42.0, -10.0)

Note: In C#, property_path must be in snake_case when referring to built-in Godot properties. Prefer using the names exposed in the PropertyName class to avoid allocating a new StringName on each call.


void set_message_translation(enable: bool) 🔗

如果設定為 true,則允許物件使用 tr()tr_n() 翻譯消息。該屬性預設啟用。另請參閱 can_translate_messages()


void set_meta(name: StringName, value: Variant) 🔗

新增或更改對象中繼資料中名稱為 name 的條目。中繼資料值 value 可以是任何 Variant,儘管某些型別無法正確序列化。

如果 valuenull,則該條目被移除。等價於使用 remove_meta()。另見 has_meta()get_meta()

注意:中繼資料的名稱 name 必須是符合 StringName.is_valid_identifier() 的有效識別字。

注意:名稱 name 以底線(_)開頭的中繼資料僅供編輯器使用。僅供編輯器使用的中繼資料不會在“屬性檢視器”中顯示,雖然仍然能夠被這個方法找到,但是不應該進行編輯。


void set_script(script: Variant) 🔗

將腳本 script 附加至該對象,並進行產生實體。因此會呼叫該腳本的 _init()Script 可用於擴充物件的功能。

如果已存在腳本,則該腳本的實例會被分離,其屬性值和狀態會丟失。仍會保留內建屬性的值。


void set_translation_domain(domain: StringName) 🔗

Sets the name of the translation domain used by tr() and tr_n(). See also TranslationServer.


String to_string() 🔗

返回表示物件的 String。預設為 "<ClassName#RID>"。覆蓋 _to_string() 以自訂物件的字串表示形式。


String tr(message: StringName, context: StringName = &"") const 🔗

Translates a message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation. Note that most Control nodes automatically translate their strings, so this method is mostly useful for formatted strings or custom drawn text.

If can_translate_messages() is false, or no translation is available, this method returns the message without changes. See set_message_translation().

For detailed examples, see Internationalizing games.

Note: This method can't be used without an Object instance, as it requires the can_translate_messages() method. To translate strings in a static context, use TranslationServer.translate().


String tr_n(message: StringName, plural_message: StringName, n: int, context: StringName = &"") const 🔗

Translates a message or plural_message, using the translation catalogs configured in the Project Settings. Further context can be specified to help with the translation.

If can_translate_messages() is false, or no translation is available, this method returns message or plural_message, without changes. See set_message_translation().

The n is the number, or amount, of the message's subject. It is used by the translation system to fetch the correct plural form for the current language.

For detailed examples, see Localization using gettext.

Note: Negative and float numbers may not properly apply to some countable subjects. It's recommended to handle these cases with tr().

Note: This method can't be used without an Object instance, as it requires the can_translate_messages() method. To translate strings in a static context, use TranslationServer.translate_plural().