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

Ereditato da: 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

Classe di base per tutte le altre classi nel motore.

Descrizione

Un tipo di Variant avanzato. Tutte le classi nel motore ereditano da Object. Ogni classe può definire nuove proprietà, metodi o segnali, che sono disponibili per tutte le classi ereditanti. Ad esempio, un'istanza Sprite2D è in grado di chiamare Node.add_child() perché eredita da Node.

Puoi creare nuove istanze, usando Object.new() in GDScript, o new GodotObject in C#.

Per eliminare un'istanza di Object, chiama free(). Ciò è necessario per la maggior parte delle classi che ereditano Object, perché non gestiscono la memoria da sole e altrimenti causeranno perdite di memoria quando non sono più in uso. Esistono alcune classi che gestiscono la loro memoria. Ad esempio, RefCounted (e per estensione Resource) elimina se stesso quando non è più referenziato e Node elimina i suoi figli quando viene liberato.

Gli oggetti possono avere uno Script allegato. Una volta istanziato lo Script, agisce effettivamente come un'estensione della classe base, consentendogli di definire ed ereditare nuove proprietà, metodi e segnali.

All'interno di uno Script, _get_property_list() può essere sovrascritto per personalizzare le proprietà in diversi modi. Ciò consente loro di essere disponibili all'editor, di essere visualizzate come liste di opzioni, di essere suddivise in gruppi, di essere salvate su disco, ecc. I linguaggi di scripting offrono modi più semplici per personalizzare le proprietà, come con l'annotazione @GDScript.@export.

Godot è molto dinamico. Lo script di un oggetto, e quindi le sue proprietà, metodi e segnali, possono essere modificati in fase di esecuzione. Per questo motivo, possono esserci occasioni in cui, ad esempio, una proprietà richiesta da un metodo potrebbe non esistere. Per evitare errori di durante l'esecuzione, vedi metodi come set(), get(), call(), has_method(), has_signal(), ecc. Nota che questi metodi sono molto più lenti dei riferimenti diretti.

In GDScript, è anche possibile verificare se una determinata proprietà, metodo o nome di segnale esiste in un oggetto con l'operatore in:

var node = Node.new()
print("name" in node)         # Stampa true
print("get_parent" in node)   # Stampa true
print("tree_entered" in node) # Stampa true
print("unknown" in node)      # Stampa false

Le notifiche sono costanti int comunemente inviate e ricevute dagli oggetti. Ad esempio, su ogni frame renderizzato, SceneTree notifica i nodi all'interno dell'albero con una Node.NOTIFICATION_PROCESS. I nodi la ricevono e possono chiamare Node._process() per aggiornarsi. Per utilizzare le notifiche, vedi notification() e _notification().

Infine, ogni oggetto può anche contenere metadati (dati sui dati). set_meta() può essere utile per memorizzare informazioni da cui l'oggetto stesso non dipende. Per mantenere pulito il codice, si sconsiglia di fare un uso eccessivo di metadati.

Nota: A differenza di riferimenti a un RefCounted, i riferimenti a un oggetto memorizzato in una variabile possono diventare non validi senza essere impostati su null. Per verificare se un oggetto è stato eliminato, non confrontarlo con null. Invece, usa @GlobalScope.is_instance_valid(). Si consiglia inoltre di ereditare da RefCounted per le classi che memorizzano dati anziché Object.

Nota: Lo script non è esposto come la maggior parte delle proprietà. Per impostare o ottenere lo Script di un oggetto in codice, usa rispettivamente set_script() e get_script().

Nota: In un contesto booleano, un Object verrà valutato come false se è uguale a null o è stato liberato. Altrimenti, un Object verrà sempre valutato come true. Vedi anche @GlobalScope.is_instance_valid().

Tutorial

Metodi

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


Segnali

property_list_changed() 🔗

Emesso quando notify_property_list_changed() viene chiamato.


script_changed() 🔗

Emesso quando lo script dell'oggetto viene cambiato.

Nota: Quando questo segnale viene emesso, il nuovo script non è ancora inizializzato. Se devi accedere al nuovo script, differisci le connessioni a questo segnale con CONNECT_DEFERRED.


Enumerazioni

flags ConnectFlags: 🔗

ConnectFlags CONNECT_DEFERRED = 1

Le connessioni differite attivano i loro Callable durante il tempo di inattività (alla fine del frame), anziché istantaneamente.

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

Le connessioni a colpo singolo si disconnettono dopo l'emissione.

ConnectFlags CONNECT_REFERENCE_COUNTED = 8

Le connessioni con conteggio dei riferimenti possono essere assegnate allo stesso Callable più volte. Ogni disconnessione diminuisce il contatore interno. Il segnale si disconnette completamente solo quando il contatore raggiunge 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>

Costanti

NOTIFICATION_POSTINITIALIZE = 0 🔗

Notifica ricevuta quando l'oggetto viene inizializzato, prima che il suo script venga allegato. Utilizzato internamente.

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 🔗

Notifica ricevuta quando l'oggetto termina il ricaricamento a caldo. Questa notifica viene inviata solo per le classi di estensioni e derivate.


Descrizioni dei metodi

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 🔗

Chiamato quando lo script dell'oggetto è istanziato, spesso dopo che l'oggetto è stato inizializzato in memoria (tramite Object.new() in GDScript, o new GodotObject in C#). Può anche essere definito per accettare parametri. Questo metodo è simile a un costruttore nella maggior parte dei linguaggi di programmazione.

Nota: Se _init() è definito con parametri obbligatori, l'oggetto con lo script può essere creato solo direttamente. Se si usano altri mezzi (come PackedScene.instantiate() o Node.duplicate()) , l'inizializzazione dello script fallirà.


Variant _iter_get(iter: Variant) virtual 🔗

Restituisce il valore iterabile attuale. iter memorizza lo stato dell'iterazione, ma a differenza di _iter_init() e _iter_next() lo stato dovrebbe essere di sola lettura, quindi non c'è alcun Array come wrapper.

Suggerimento: in GDScript, è possibile usare un sottotipo di Variant come tipo restituito per _iter_get(). Il tipo specificato sarà usato per impostare il tipo della variabile iteratore nei cicli for, garantendo migliore sicurezza di tipo.


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 🔗

Sposta l'iteratore all'iterazione successiva. iter memorizza lo stato dell'iterazione. Poiché GDScript non supporta il passaggio di argomenti per riferimento, viene utilizzato un array con un singolo elemento come wrapper. Restituisce true finché l'iteratore non ha raggiunto la fine.


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 🔗

Sovrascrivi questo metodo per personalizzare il valore restituito da to_string() e quindi la rappresentazione dell'oggetto come String.

func _to_string():
    return "Benvenuto su Godot 4!"

func _init():
    print(self)       # Stampa "Benvenuto su Godot 4!"
    var a = str(self) # a è "Benvenuto su Godot 4!"

void _validate_property(property: Dictionary) virtual 🔗

Sovrascrivi questo metodo per personalizzare le proprietà esistenti. Ogni informazione sulle proprietà passa attraverso questo metodo, tranne le proprietà aggiunte con _get_property_list(). Il contenuto del dizionario è lo stesso di _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 = []) 🔗

Aggiunge un segnale definito dall'utente con il nome signal. È possibile aggiungere argomenti opzionali per il segnale come un Array di dizionari, ognuno dei quali definisce un nome (name) String e un tipo (type) int (vedi Variant.Type). Vedi anche has_user_signal() e remove_user_signal().

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

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

Chiama il metodo denominato method sull'oggetto e restituisce il risultato. Questo metodo supporta un numero variabile di argomenti, quindi è possibile passare i parametri come un elenco separato da virgole.

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

Nota: In C#, method deve essere in snake_case quando si fa riferimento ai metodi integrati di Godot. Preferisci usare i nomi esposti nella classe MethodName per evitare di allocare un nuovo StringName a ogni chiamata.


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) 🔗

Chiama il metodo denominato method sull'oggetto e ne restituisce il risultato. A differenza di call(), questo metodo si aspetta che tutti i parametri siano contenuti all'interno di arg_array.

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

Nota: In C#, method deve essere in snake_case quando si fa riferimento ai metodi integrati di Godot. Preferisci usare i nomi esposti nella classe MethodName per evitare di allocare un nuovo StringName a ogni chiamata.


bool can_translate_messages() const 🔗

Restituisce true se all'oggetto è permesso tradurre i messaggi con tr() e tr_n(). Vedi anche set_message_translation().


void cancel_free() 🔗

Se questo metodo viene chiamato durante NOTIFICATION_PREDELETE, questo oggetto rifiuterà di liberarsi e rimarrà allocato. Questa è principalmente una funzione interna utilizzata per la gestione degli errori per evitare che l'utente liberi oggetti quando non è previsto.


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) 🔗

Disconnette il segnale denominato signal dal chiamabile callable. Se la connessione non esiste, genera un errore. Usa is_connected() per assicurarti che la connessione esista.


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

Emette il segnale signal per nome. Il segnale deve esistere, quindi dovrebbe essere un segnale integrato di questa classe o di una delle sue classi ereditate, o un segnale definito dall'utente (vedi add_user_signal()). Questo metodo supporta un numero variabile di argomenti, quindi è possibile passare i parametri come un elenco separato da virgole.

Restituisce @GlobalScope.ERR_UNAVAILABLE se signal non esiste o i parametri non sono validi.

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

Nota: In C#, signal deve essere in snake_case quando si fa riferimento ai segnali integrati di Godot. Preferisci usare i nomi esposti nella classe SignalName per evitare di allocare un nuovo StringName a ogni chiamata.


void free() 🔗

Elimina l'oggetto dalla memoria. I riferimenti preesistenti all'oggetto diventano non validi e qualsiasi tentativo di accedervi causerà un errore di esecuzione. Verificare i riferimenti con @GlobalScope.is_instance_valid() restituirà false. Questo è equivalente alla funzione memdelete in GDExtension C++.


Variant get(property: StringName) const 🔗

Restituisce il valore Variant della proprietà property specificata. Se la proprietà property non esiste, questo metodo restituisce null.

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

Nota: In C#, property deve essere in snake_case quando si fa riferimento alle proprietà integrate di Godot. Preferisci utilizzare i nomi esposti nella classe PropertyName per evitare di allocare un nuovo StringName a ogni chiamata.


String get_class() const 🔗

Restituisce il nome della classe integrata dell'oggetto, come String. Vedi anche is_class().

Nota: Questo metodo ignora le dichiarazioni class_name. Se lo script di questo oggetto ha definito un class_name, viene restituito invece il nome della classe integrata di base.


Array[Dictionary] get_incoming_connections() const 🔗

Restituisce un Array di connessioni di segnale ricevute da questo oggetto. Ogni connessione è rappresentata come un Dictionary che contiene tre voci:


Variant get_indexed(property_path: NodePath) const 🔗

Ottiene la proprietà dell'oggetto indicizzata dal parametro property_path specificato. Il percorso deve essere un NodePath relativo all'oggetto attuale e può utilizzare il carattere due punti (:) per accedere alle proprietà innestate.

Esempi: "position:x" o "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

Nota: In C#, property_path deve essere in snake_case quando si fa riferimento alle proprietà integrate di Godot. Preferisci usare i nomi esposti nella classe PropertyName per evitare di allocare un nuovo StringName a ogni chiamata.

Nota: Questo metodo non supporta percorsi per i nodi in SceneTree, solo percorsi di sotto-proprietà. Nel contesto dei nodi, usa invece Node.get_node_and_resource().


int get_instance_id() const 🔗

Restituisce l'ID univoco di istanza dell'oggetto. Questo ID può essere salvato in EncodedObjectAsID e può essere utilizzato per recuperare questa istanza di oggetto con @GlobalScope.instance_from_id().

Nota: Questo ID è utile solo durante la sessione attuale. Non corrisponderà a un oggetto simile se l'ID viene inviato tramite rete o caricato da un file in un secondo momento.


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

Restituisce il valore del metadato dell'oggetto per la voce name specificata. Se la voce non esiste, restituisce default. Se default è null, viene generato anche un errore.

Nota: Il nome di un metadato deve essere un identificatore valido come per il metodo StringName.is_valid_identifier().

Nota: I metadati che hanno un nome che inizia con un trattino basso (_) sono considerati solo per l'editor. I metadati solo per l'editor non sono visualizzati nell'Ispettore e non dovrebbero essere modificati, sebbene si possano comunque trovare con questo metodo.


Array[StringName] get_meta_list() const 🔗

Restituisce i nomi delle voci dei metadati dell'oggetto come un Array di StringName.


int get_method_argument_count(method: StringName) const 🔗

Restituisce il numero di argomenti del metodo method specificato per nome.

Nota: In C#, method deve essere in snake_case quando si fa riferimento ai metodi integrati di Godot. Preferisci usare i nomi esposti nella classe MethodName per evitare di allocare un nuovo StringName a ogni chiamata.


Array[Dictionary] get_method_list() const 🔗

Restituisce i metodi di questo oggetto e le loro firme sotto forma di un Array di dizionari. Ogni Dictionary contiene le seguenti voci:

  • name è il nome del metodo, come String;

  • args è un Array di dizionari che rappresentano gli argomenti;

  • default_args sono gli argomenti predefiniti come Array di varianti;

  • flags è una combinazione di MethodFlags;

  • id è l'identificatore interno del metodo, come int;

  • return è il valore restituito, come Dictionary;

Nota: I dizionari di args e return sono formattati in modo identico ai risultati di get_property_list(), sebbene non vengano utilizzate tutte le voci.


Array[Dictionary] get_property_list() const 🔗

Restituisce la lista delle proprietà dell'oggetto come Array di dizionari. Ogni Dictionary contiene le seguenti voci:

Nota: In GDScript, tutti i membri di una classe sono trattati come proprietà. In C# e GDExtension potrebbe essere necessario contrassegnare esplicitamente i membri di una classe come proprietà di Godot utilizzando decoratori o attributi.


Variant get_script() const 🔗

Restituisce l'istanza dello Script dell'oggetto oppure null se nessuno script è allegato.


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

Restituisce un Array di connessioni per il segnale denominato signal. Ogni connessione è rappresentata come Dictionary che contiene tre voci:


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 🔗

Restituisce il nome del dominio di traduzione usato da tr() e tr_n(). Vedi anche TranslationServer.


bool has_connections(signal: StringName) const 🔗

Restituisce true se esiste una qualsiasi connessione al segnale con il nome signal.

Nota: In C#, signal deve essere in snake_case quando si fa riferimento ai metodi integrati di Godot. Preferisci usare i nomi esposti nella classe SignalName per evitare di allocare un nuovo StringName a ogni chiamata.


bool has_meta(name: StringName) const 🔗

Restituisce true se viene trovata una voce di metadati con il nome name. Vedi anche get_meta(), set_meta() e remove_meta().

Nota: Il nome di un metadato deve essere un identificatore valido come per il metodo StringName.is_valid_identifier().

Nota: I metadati che hanno un nome che inizia con un trattino basso (_) sono considerati solo per l'editor. I metadati solo per l'editor non sono visualizzati nell'Ispettore e non dovrebbero essere modificati, sebbene si possano comunque trovare con questo metodo.


bool has_method(method: StringName) const 🔗

Restituisce true se un metodo con il nome method esiste nell'oggetto.

Nota: In C#, method deve essere in snake_case quando si fa riferimento ai metodi integrati di Godot. Preferisci usare i nomi esposti nella classe MethodName per evitare di allocare un nuovo StringName a ogni chiamata.


bool has_signal(signal: StringName) const 🔗

Restituisce true se un segnale con il nome signal esiste nell'oggetto.

Nota: In C#, signal deve essere in snake_case quando si fa riferimento ai segnali integrati di Godot. Preferisci usare i nomi esposti nella classe SignalName per evitare di allocare un nuovo StringName a ogni chiamata.


bool has_user_signal(signal: StringName) const 🔗

Restituisce true se esiste il segnale definito dall'utente con il nome signal. Sono inclusi solo i segnali aggiunti con add_user_signal(). Vedi anche remove_user_signal().


bool is_blocking_signals() const 🔗

Restituisce true se l'oggetto sta bloccando l'emissione dei suoi segnali. Vedi set_block_signals().


bool is_class(class: StringName) const 🔗

Restituisce true se l'oggetto eredita dalla classe class specificata. Vedi anche get_class().

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

Nota: Questo metodo ignora le dichiarazioni di class_name nello script dell'oggetto.


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

Restituisce true se esiste una connessione tra il segnale con il nome signal e callable.

Nota: In C#, signal deve essere in snake_case quando si fa riferimento ai segnali integrati di Godot. Preferisci usare i nomi esposti nella classe SignalName per evitare di allocare un nuovo StringName a ogni chiamata.


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) 🔗

Invia la notifica what specificata a tutte le classi ereditate dall'oggetto, attivando le chiamate a _notification(), a partire dall'antenato più alto (la classe Object) e arrivando fino allo script dell'oggetto.

Se reversed è true, l'ordine delle chiamate è invertito.

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

player.notification(NOTIFICATION_ENTER_TREE)
# L'ordine delle chiamate è Object -> Node -> Node2D -> player.gd.

player.notification(NOTIFICATION_ENTER_TREE, true)
# L'ordine delle chiamate è player.gd -> Node2D -> Node -> Object.

void notify_property_list_changed() 🔗

Emette il segnale property_list_changed. È utilizzato principalmente per aggiornare l'editor, in modo che le estensioni dell'editor e l'Ispettore siano aggiornati correttamente.


bool property_can_revert(property: StringName) const 🔗

Restituisce true se la proprietà property specificata ha un valore predefinito personalizzato. Usa property_get_revert() per ottenere il valore predefinito di property.

Nota: Questo metodo è utilizzato dal pannello dell'Ispettore per visualizzare un'icona di ripristino. L'oggetto deve implementare _property_can_revert() per personalizzare il valore predefinito. Se _property_can_revert() non è implementato, questo metodo restituisce false.


Variant property_get_revert(property: StringName) const 🔗

Restituisce il valore predefinito personalizzato della proprietà property specificata. Usa property_can_revert() per verificare se la proprietà property ha un valore predefinito personalizzato.

Nota: Questo metodo è utilizzato dal pannello dell'Ispettore per visualizzare un'icona di ripristino. L'oggetto deve implementare _property_get_revert() per personalizzare il valore predefinito. Se _property_get_revert() non è implementato, questo metodo restituisce null.


void remove_meta(name: StringName) 🔗

Rimuove la voce con il nome name dai metadati dell'oggetto. Vedi anche has_meta(), get_meta() e set_meta().

Nota: Il nome di un metadato deve essere un identificatore valido come per il metodo StringName.is_valid_identifier().

Nota: I metadati che hanno un nome che inizia con un trattino basso (_) sono considerati solo per l'editor. I metadati solo per l'editor non sono visualizzati nell'Ispettore e non dovrebbero essere modificati, sebbene si possano comunque trovare con questo metodo.


void remove_user_signal(signal: StringName) 🔗

Rimuove il segnale utente con il nome signal dall'oggetto. Vedi anche add_user_signal() e has_user_signal().


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

Assegna value alla proprietà property specificata. Se la proprietà non esiste o il tipo del valore value non corrisponde, non succede nulla.

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

Nota: In C#, property deve essere in snake_case quando si fa riferimento alle proprietà integrate di Godot. Preferisci utilizzare i nomi esposti nella classe PropertyName per evitare di allocare un nuovo StringName a ogni chiamata.


void set_block_signals(enable: bool) 🔗

Se impostato su true, l'oggetto non è più in grado di emettere segnali. Di conseguenza, emit_signal() e le connessioni dei segnali non funzioneranno, finché non sarà impostato su false.


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

Assegna value alla proprietà property specificata, alla fine del frame attuale. Ciò equivale a chiamare set() tramite call_deferred().

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

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

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

Nota: in C#, property deve essere in snake_case quando si fa riferimento alle proprietà integrate di Godot. Preferisci usare i nomi esposti nella classe PropertyName per evitare di allocare un nuovo StringName a ogni chiamata.


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

Assegna un nuovo value alla proprietà identificata da property_path. Il percorso dovrebbe essere un NodePath relativo a questo oggetto e può utilizzare il carattere due punti (:) per accedere alle proprietà innestate.

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

Nota: In C#, property_path deve essere in snake_case quando si fa riferimento alle proprietà integrate di Godot. Preferisci usare i nomi esposti nella classe PropertyName per evitare di allocare un nuovo StringName a ogni chiamata.


void set_message_translation(enable: bool) 🔗

Se impostato su true, consente all'oggetto di tradurre i messaggi con tr() e tr_n(). Abilitato per impostazione predefinita. Vedi anche can_translate_messages().


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

Aggiunge o modifica la voce con il nome name all'interno dei metadati dell'oggetto. Per i metadati, value può essere un qualsiasi Variant, nonostante alcuni tipi non si possano serializzare correttamente.

Se value è null, la voce viene rimossa. Ciò equivale a usare remove_meta(). Vedi anche has_meta() e get_meta().

Nota: il nome di un metadato deve essere un identificatore valido come per il metodo StringName.is_valid_identifier().

Nota: I metadati che hanno un nome che inizia con un trattino basso (_) sono considerati solo per l'editor. I metadati solo per l'editor non sono visualizzati nell'Ispettore e non dovrebbero essere modificati, sebbene si possano comunque trovare con questo metodo.


void set_script(script: Variant) 🔗

Allega script all'oggetto e ne crea un'istanza. Di conseguenza, viene chiamato il _init() dello script. Uno Script serve per estendere la funzionalità dell'oggetto.

Se uno script esiste già, la sua istanza viene staccata e i suoi valori di proprietà e lo stato vengono persi. I valori di proprietà integrate vengono comunque mantenuti.


void set_translation_domain(domain: StringName) 🔗

Imposta il nome del dominio di traduzione usato da tr() e tr_n(). Vedi anche TranslationServer.


String to_string() 🔗

Restituisce una String che rappresenta l'oggetto. Il valore predefinito è "<ClassName#RID>". Sovrascrivi _to_string() per personalizzare la rappresentazione in stringa dell'oggetto.


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

Traduce la stringa message, utilizzando i cataloghi di traduzione configurati nelle Impostazioni del progetto. È possibile specificare un ulteriore contesto (context) per facilitare la traduzione. Nota che la maggior parte dei nodi Control traduce automaticamente le proprie stringhe, quindi questo metodo è utile soprattutto per stringhe formattate o testo disegnato personalizzato.

Se can_translate_messages() è false, o nessuna traduzione è disponibile, questo metodo restituisce message senza modifiche. Vedi set_message_translation().

Per esempi dettagliati, consulta Internazionalizzazione dei giochi.

Nota: Questo metodo non può essere utilizzato senza un'istanza di Object, poiché richiede il metodo can_translate_messages(). Per tradurre delle stringhe in un contesto statico, usa TranslationServer.translate().


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

Traduce la stringa message o plural_message, utilizzando i cataloghi di traduzione configurati nelle Impostazioni del progetto. È possibile specificare un ulteriore contesto (context) per facilitare la traduzione.

Se can_translate_messages() è false o nessuna traduzione è disponibile, questo metodo restituisce message o plural_message, senza modifiche. Vedi set_message_translation().

n è il numero, o la quantità, del soggetto del messaggio. È utilizzato dal sistema di traduzione per recuperare la forma plurale corretta per la lingua attuale.

Per esempi dettagliati, consulta Localizzazione tramite gettext.

Nota: I numeri negativi e float potrebbero non essere applicati correttamente ad alcuni soggetti numerabili. Si consiglia di gestire questi casi con tr().

Nota: Questo metodo non può essere utilizzato senza un'istanza di Object, poiché richiede il metodo can_translate_messages(). Per tradurre delle stringhe in un contesto statico, usa TranslationServer.translate_plural().