mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
1804 lines
124 KiB
ReStructuredText
1804 lines
124 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_Object:
|
||
|
||
Object
|
||
======
|
||
|
||
**Успадковано від:** :ref:`AudioServer<class_AudioServer>`, :ref:`CameraServer<class_CameraServer>`, :ref:`ClassDB<class_ClassDB>`, :ref:`DisplayServer<class_DisplayServer>`, :ref:`EditorFileSystemDirectory<class_EditorFileSystemDirectory>`, :ref:`EditorInterface<class_EditorInterface>`, :ref:`EditorPaths<class_EditorPaths>`, :ref:`EditorSelection<class_EditorSelection>`, :ref:`EditorUndoRedoManager<class_EditorUndoRedoManager>`, :ref:`EditorVCSInterface<class_EditorVCSInterface>`, :ref:`Engine<class_Engine>`, :ref:`EngineDebugger<class_EngineDebugger>`, :ref:`FramebufferCacheRD<class_FramebufferCacheRD>`, :ref:`GDExtensionManager<class_GDExtensionManager>`, :ref:`Geometry2D<class_Geometry2D>`, :ref:`Geometry3D<class_Geometry3D>`, :ref:`GodotInstance<class_GodotInstance>`, :ref:`Input<class_Input>`, :ref:`InputMap<class_InputMap>`, :ref:`IP<class_IP>`, :ref:`JavaClassWrapper<class_JavaClassWrapper>`, :ref:`JavaScriptBridge<class_JavaScriptBridge>`, :ref:`JNISingleton<class_JNISingleton>`, :ref:`JSONRPC<class_JSONRPC>`, :ref:`MainLoop<class_MainLoop>`, :ref:`Marshalls<class_Marshalls>`, :ref:`MovieWriter<class_MovieWriter>`, :ref:`NativeMenu<class_NativeMenu>`, :ref:`NavigationMeshGenerator<class_NavigationMeshGenerator>`, :ref:`NavigationServer2D<class_NavigationServer2D>`, :ref:`NavigationServer2DManager<class_NavigationServer2DManager>`, :ref:`NavigationServer3D<class_NavigationServer3D>`, :ref:`NavigationServer3DManager<class_NavigationServer3DManager>`, :ref:`Node<class_Node>`, :ref:`OpenXRExtensionWrapper<class_OpenXRExtensionWrapper>`, :ref:`OpenXRInteractionProfileMetadata<class_OpenXRInteractionProfileMetadata>`, :ref:`OS<class_OS>`, :ref:`Performance<class_Performance>`, :ref:`PhysicsDirectBodyState2D<class_PhysicsDirectBodyState2D>`, :ref:`PhysicsDirectBodyState3D<class_PhysicsDirectBodyState3D>`, :ref:`PhysicsDirectSpaceState2D<class_PhysicsDirectSpaceState2D>`, :ref:`PhysicsDirectSpaceState3D<class_PhysicsDirectSpaceState3D>`, :ref:`PhysicsServer2D<class_PhysicsServer2D>`, :ref:`PhysicsServer2DManager<class_PhysicsServer2DManager>`, :ref:`PhysicsServer3D<class_PhysicsServer3D>`, :ref:`PhysicsServer3DManager<class_PhysicsServer3DManager>`, :ref:`PhysicsServer3DRenderingServerHandler<class_PhysicsServer3DRenderingServerHandler>`, :ref:`ProjectSettings<class_ProjectSettings>`, :ref:`RefCounted<class_RefCounted>`, :ref:`RenderData<class_RenderData>`, :ref:`RenderingDevice<class_RenderingDevice>`, :ref:`RenderingServer<class_RenderingServer>`, :ref:`RenderSceneData<class_RenderSceneData>`, :ref:`ResourceLoader<class_ResourceLoader>`, :ref:`ResourceSaver<class_ResourceSaver>`, :ref:`ResourceUID<class_ResourceUID>`, :ref:`ScriptLanguage<class_ScriptLanguage>`, :ref:`ShaderIncludeDB<class_ShaderIncludeDB>`, :ref:`TextServerManager<class_TextServerManager>`, :ref:`ThemeDB<class_ThemeDB>`, :ref:`TileData<class_TileData>`, :ref:`Time<class_Time>`, :ref:`TranslationServer<class_TranslationServer>`, :ref:`TreeItem<class_TreeItem>`, :ref:`UndoRedo<class_UndoRedo>`, :ref:`UniformSetCacheRD<class_UniformSetCacheRD>`, :ref:`WorkerThreadPool<class_WorkerThreadPool>`, :ref:`XRServer<class_XRServer>`, :ref:`XRVRS<class_XRVRS>`
|
||
|
||
Базовий клас для всіх інших класів двигуна.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Опис
|
||
--------
|
||
|
||
Розширений тип :ref:`Variant<class_Variant>`. Усі класи в двигуні успадковуються від Object. Кожен клас може визначати нові властивості, методи або сигнали, які доступні для всіх успадкованих класів. Наприклад, екземпляр :ref:`Sprite2D<class_Sprite2D>` може викликати :ref:`Node.add_child()<class_Node_method_add_child>`, оскільки він успадковує :ref:`Node<class_Node>`.
|
||
|
||
Ви можете створювати нові екземпляри за допомогою ``Object.new()`` у GDScript або ``new GodotObject`` у C#.
|
||
|
||
Щоб видалити примірник Object, викличте :ref:`free()<class_Object_method_free>`. Це необхідно для більшості класів, які успадковують Object, тому що вони не керують пам’яттю самостійно, і в іншому випадку призведуть до витоків пам’яті, коли вони більше не використовуються. Є кілька класів, які виконують керування пам'яттю. Наприклад, :ref:`RefCounted<class_RefCounted>` (і за розширенням :ref:`Resource<class_Resource>`) видаляє себе, коли на нього більше не посилаються, а :ref:`Node<class_Node>` видаляє своїх дочірніх елементів, коли звільняється.
|
||
|
||
До об’єктів може бути прикріплений :ref:`Script<class_Script>`. Після того, як :ref:`Script<class_Script>` створено, він фактично діє як розширення базового класу, дозволяючи йому визначати та успадковувати нові властивості, методи та сигнали.
|
||
|
||
У :ref:`Script<class_Script>` :ref:`_get_property_list()<class_Object_private_method__get_property_list>` можна замінити, щоб налаштувати властивості кількома способами. Це дозволяє їм бути доступними для редактора, відображатися як списки параметрів, ділитися на групи, зберігати на диску тощо. Мови сценаріїв пропонують прості способи налаштування властивостей, наприклад, за допомогою анотації :ref:`@GDScript.@export<class_@GDScript_annotation_@export>`.
|
||
|
||
Godot дуже динамічний. Скрипт об’єкта, а отже, його властивості, методи та сигнали можна змінювати під час виконання. Через це можуть бути випадки, коли, наприклад, властивість, необхідна для методу, може не існувати. Щоб запобігти помилкам під час виконання, перегляньте такі методи, як :ref:`set()<class_Object_method_set>`, :ref:`get()<class_Object_method_get>`, :ref:`call()<class_Object_method_call>`, :ref:`has_method()<class_Object_method_has_method>`, :ref:`has_signal()<class_Object_method_has_signal>` тощо. Зауважте, що ці методи **набагато** повільніші за прямі посилання.
|
||
|
||
У GDScript ви також можете перевірити, чи властивість, метод або ім’я сигналу існує в об’єкті за допомогою оператора ``in``:
|
||
|
||
::
|
||
|
||
var node = Node.new()
|
||
print("name" in node) # Друкує true
|
||
print("get_parent" in node) # Виводить true
|
||
print("tree_entered" in node) # Виводить true
|
||
print("unknown" in node) # Виводить false
|
||
|
||
Сповіщення — це константи :ref:`int<class_int>`, які зазвичай надсилаються й отримуються об’єктами. Наприклад, у кожному відтвореному кадрі :ref:`SceneTree<class_SceneTree>` сповіщає вузли всередині дерева за допомогою :ref:`Node.NOTIFICATION_PROCESS<class_Node_constant_NOTIFICATION_PROCESS>`. Вузли отримують його та можуть викликати :ref:`Node._process()<class_Node_private_method__process>` для оновлення. Щоб скористатися сповіщеннями, перегляньте :ref:`notification()<class_Object_method_notification>` і :ref:`_notification()<class_Object_private_method__notification>`.
|
||
|
||
Нарешті, кожен об’єкт також може містити метадані (дані про дані). :ref:`set_meta()<class_Object_method_set_meta>` може бути корисним для зберігання інформації, від якої не залежить сам об’єкт. Щоб ваш код був чистим, не рекомендується надмірне використання метаданих.
|
||
|
||
\ **Примітка:** На відміну від посилань на :ref:`RefCounted<class_RefCounted>`, посилання на об’єкт, що зберігається у змінній, можуть стати недійсними без встановлення значення ``null``. Щоб перевірити, чи об’єкт видалено, *не* порівнюйте його з ``null``. Натомість використовуйте :ref:`@GlobalScope.is_instance_valid()<class_@GlobalScope_method_is_instance_valid>`. Також рекомендується успадкувати від :ref:`RefCounted<class_RefCounted>` для класів, які зберігають дані замість **Object**.
|
||
|
||
\ **Примітка:** ``script`` не доступний, як більшість властивостей. Щоб встановити або отримати :ref:`Script<class_Script>` об’єкта в коді, використовуйте :ref:`set_script()<class_Object_method_set_script>` і :ref:`get_script()<class_Object_method_get_script>` відповідно.
|
||
|
||
\ **Примітка: ** У логічному контексті **Object** матиме значення ``false``, якщо він дорівнює ``null`` або його було звільнено. В іншому випадку **Object** завжди матиме значення ``true``. Дивіться також :ref:`@GlobalScope.is_instance_valid()<class_@GlobalScope_method_is_instance_valid>`.
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
Посібники
|
||
------------------
|
||
|
||
- :doc:`Введення об'єктів <../engine_details/architecture/object_class>`
|
||
|
||
- :doc:`Коли і як уникнути використання вузлів для всіх <../tutorials/best_practices/node_alternatives>`
|
||
|
||
- :doc:`Повідомлення про об'єкт <../tutorials/best_practices/godot_notifications>`
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
Методи
|
||
------------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`_get<class_Object_private_method__get>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`_get_property_list<class_Object_private_method__get_property_list>`\ (\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`_init<class_Object_private_method__init>`\ (\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`_iter_get<class_Object_private_method__iter_get>`\ (\ iter\: :ref:`Variant<class_Variant>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`_iter_init<class_Object_private_method__iter_init>`\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`_iter_next<class_Object_private_method__iter_next>`\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`_notification<class_Object_private_method__notification>`\ (\ what\: :ref:`int<class_int>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`_property_can_revert<class_Object_private_method__property_can_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`_property_get_revert<class_Object_private_method__property_get_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`_set<class_Object_private_method__set>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`_to_string<class_Object_private_method__to_string>`\ (\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`_validate_property<class_Object_private_method__validate_property>`\ (\ property\: :ref:`Dictionary<class_Dictionary>`\ ) |virtual| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`add_user_signal<class_Object_method_add_user_signal>`\ (\ signal\: :ref:`String<class_String>`, arguments\: :ref:`Array<class_Array>` = []\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`call<class_Object_method_call>`\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`call_deferred<class_Object_method_call_deferred>`\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`callv<class_Object_method_callv>`\ (\ method\: :ref:`StringName<class_StringName>`, arg_array\: :ref:`Array<class_Array>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`can_translate_messages<class_Object_method_can_translate_messages>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`cancel_free<class_Object_method_cancel_free>`\ (\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`connect<class_Object_method_connect>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`, flags\: :ref:`int<class_int>` = 0\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`disconnect<class_Object_method_disconnect>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Error<enum_@GlobalScope_Error>` | :ref:`emit_signal<class_Object_method_emit_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`free<class_Object_method_free>`\ (\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get<class_Object_method_get>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`get_class<class_Object_method_get_class>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_incoming_connections<class_Object_method_get_incoming_connections>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_indexed<class_Object_method_get_indexed>`\ (\ property_path\: :ref:`NodePath<class_NodePath>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_instance_id<class_Object_method_get_instance_id>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_meta<class_Object_method_get_meta>`\ (\ name\: :ref:`StringName<class_StringName>`, default\: :ref:`Variant<class_Variant>` = null\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`StringName<class_StringName>`\] | :ref:`get_meta_list<class_Object_method_get_meta_list>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`get_method_argument_count<class_Object_method_get_method_argument_count>`\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_method_list<class_Object_method_get_method_list>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_property_list<class_Object_method_get_property_list>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`get_script<class_Object_method_get_script>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_signal_connection_list<class_Object_method_get_signal_connection_list>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] | :ref:`get_signal_list<class_Object_method_get_signal_list>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`StringName<class_StringName>` | :ref:`get_translation_domain<class_Object_method_get_translation_domain>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_connections<class_Object_method_has_connections>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_meta<class_Object_method_has_meta>`\ (\ name\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_method<class_Object_method_has_method>`\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_signal<class_Object_method_has_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`has_user_signal<class_Object_method_has_user_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_blocking_signals<class_Object_method_is_blocking_signals>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_class<class_Object_method_is_class>`\ (\ class\: :ref:`String<class_String>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_connected<class_Object_method_is_connected>`\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_queued_for_deletion<class_Object_method_is_queued_for_deletion>`\ (\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`notification<class_Object_method_notification>`\ (\ what\: :ref:`int<class_int>`, reversed\: :ref:`bool<class_bool>` = false\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`notify_property_list_changed<class_Object_method_notify_property_list_changed>`\ (\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`property_can_revert<class_Object_method_property_can_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Variant<class_Variant>` | :ref:`property_get_revert<class_Object_method_property_get_revert>`\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`remove_meta<class_Object_method_remove_meta>`\ (\ name\: :ref:`StringName<class_StringName>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`remove_user_signal<class_Object_method_remove_user_signal>`\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set<class_Object_method_set>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_block_signals<class_Object_method_set_block_signals>`\ (\ enable\: :ref:`bool<class_bool>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_deferred<class_Object_method_set_deferred>`\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_indexed<class_Object_method_set_indexed>`\ (\ property_path\: :ref:`NodePath<class_NodePath>`, value\: :ref:`Variant<class_Variant>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_message_translation<class_Object_method_set_message_translation>`\ (\ enable\: :ref:`bool<class_bool>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_meta<class_Object_method_set_meta>`\ (\ name\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_script<class_Object_method_set_script>`\ (\ script\: :ref:`Variant<class_Variant>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| |void| | :ref:`set_translation_domain<class_Object_method_set_translation_domain>`\ (\ domain\: :ref:`StringName<class_StringName>`\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`to_string<class_Object_method_to_string>`\ (\ ) |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`tr<class_Object_method_tr>`\ (\ message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`String<class_String>` | :ref:`tr_n<class_Object_method_tr_n>`\ (\ message\: :ref:`StringName<class_StringName>`, plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| |
|
||
+------------------------------------------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Сигнали
|
||
--------------
|
||
|
||
.. _class_Object_signal_property_list_changed:
|
||
|
||
.. rst-class:: classref-signal
|
||
|
||
**property_list_changed**\ (\ ) :ref:`🔗<class_Object_signal_property_list_changed>`
|
||
|
||
Випромінюється, коли :ref:`notify_property_list_changed()<class_Object_method_notify_property_list_changed>` називається.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_signal_script_changed:
|
||
|
||
.. rst-class:: classref-signal
|
||
|
||
**script_changed**\ (\ ) :ref:`🔗<class_Object_signal_script_changed>`
|
||
|
||
Увімкнено, коли змінено скрипт об’єкта.
|
||
|
||
\ **Примітка:** Коли цей сигнал видається, новий скрипт ще не ініціюється. Якщо вам необхідно отримати доступ до нового скрипту, з'єднання знеболюючим сигналом з :ref:`CONNECT_DEFERRED<class_Object_constant_CONNECT_DEFERRED>`.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Переліки
|
||
----------------
|
||
|
||
.. _enum_Object_ConnectFlags:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **ConnectFlags**: :ref:`🔗<enum_Object_ConnectFlags>`
|
||
|
||
.. _class_Object_constant_CONNECT_DEFERRED:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_DEFERRED** = ``1``
|
||
|
||
З'єднання знезабарвленими з'єднаннями спрацьовуються на час свічок (в кінці рами), а не миттєво.
|
||
|
||
.. _class_Object_constant_CONNECT_PERSIST:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_PERSIST** = ``2``
|
||
|
||
Persisting connections are stored when the object is serialized (such as when using :ref:`PackedScene.pack()<class_PackedScene_method_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 :ref:`connect()<class_Object_method_connect>` call) cannot be made persistent.
|
||
|
||
.. _class_Object_constant_CONNECT_ONE_SHOT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_ONE_SHOT** = ``4``
|
||
|
||
З'єднання з одним знімком відключають себе після емісії.
|
||
|
||
.. _class_Object_constant_CONNECT_REFERENCE_COUNTED:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_REFERENCE_COUNTED** = ``8``
|
||
|
||
З'єднання з обліковими записами можуть бути призначені для того ж ``з урахуванням`` декількох разів. Кожен відключення зменшує внутрішню протидію. Повністю відключається сигнал, коли лічильник досягає 0.
|
||
|
||
.. _class_Object_constant_CONNECT_APPEND_SOURCE_OBJECT:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`ConnectFlags<enum_Object_ConnectFlags>` **CONNECT_APPEND_SOURCE_OBJECT** = ``16``
|
||
|
||
Вихідний об'єкт автоматично прив'язується, коли створюється екземпляр :ref:`PackedScene<class_PackedScene>`. Якщо цей біт прапорця увімкнено, вихідний об'єкт буде додано одразу після початкових аргументів сигналу.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Константи
|
||
------------------
|
||
|
||
.. _class_Object_constant_NOTIFICATION_POSTINITIALIZE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**NOTIFICATION_POSTINITIALIZE** = ``0`` :ref:`🔗<class_Object_constant_NOTIFICATION_POSTINITIALIZE>`
|
||
|
||
Повідомлення, отримане при ініціалізації об'єкта, перед його скриптом кріпиться. Використовується внутрішньо.
|
||
|
||
.. _class_Object_constant_NOTIFICATION_PREDELETE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**NOTIFICATION_PREDELETE** = ``1`` :ref:`🔗<class_Object_constant_NOTIFICATION_PREDELETE>`
|
||
|
||
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.
|
||
|
||
.. _class_Object_constant_NOTIFICATION_EXTENSION_RELOADED:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**NOTIFICATION_EXTENSION_RELOADED** = ``2`` :ref:`🔗<class_Object_constant_NOTIFICATION_EXTENSION_RELOADED>`
|
||
|
||
Повідомлення отримано при обробці об'єкта гарячим перевантаженням. Це повідомлення надсилається тільки для занять розширеннями та отриманими.
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
Описи методів
|
||
--------------------------
|
||
|
||
.. _class_Object_private_method__get:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **_get**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`🔗<class_Object_private_method__get>`
|
||
|
||
Override this method to customize the behavior of :ref:`get()<class_Object_method_get>`. Should return the given ``property``'s value, or ``null`` if the ``property`` should be handled normally.
|
||
|
||
Combined with :ref:`_set()<class_Object_private_method__set>` and :ref:`_get_property_list()<class_Object_private_method__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 :ref:`@GDScript.@export<class_@GDScript_annotation_@export>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
func _get(property):
|
||
if property == "fake_property":
|
||
print("Getting my property!")
|
||
return 4
|
||
|
||
func _get_property_list():
|
||
return [
|
||
{ "name": "fake_property", "type": TYPE_INT }
|
||
]
|
||
|
||
.. code-tab:: csharp
|
||
|
||
public override Variant _Get(StringName property)
|
||
{
|
||
if (property == "FakeProperty")
|
||
{
|
||
GD.Print("Getting my property!");
|
||
return 4;
|
||
}
|
||
return default;
|
||
}
|
||
|
||
public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
|
||
{
|
||
return
|
||
[
|
||
new Godot.Collections.Dictionary()
|
||
{
|
||
{ "name", "FakeProperty" },
|
||
{ "type", (int)Variant.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.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__get_property_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **_get_property_list**\ (\ ) |virtual| :ref:`🔗<class_Object_private_method__get_property_list>`
|
||
|
||
Override this method to provide a custom list of additional properties to handle by the engine.
|
||
|
||
Should return a property list, as an :ref:`Array<class_Array>` of dictionaries. The result is added to the array of :ref:`get_property_list()<class_Object_method_get_property_list>`, and should be formatted in the same way. Each :ref:`Dictionary<class_Dictionary>` must at least contain the ``name`` and ``type`` entries.
|
||
|
||
You can use :ref:`_property_can_revert()<class_Object_private_method__property_can_revert>` and :ref:`_property_get_revert()<class_Object_private_method__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:
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
@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 = []
|
||
|
||
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]
|
||
|
||
func _set(property, value):
|
||
if property.begins_with("number_"):
|
||
var index = property.get_slice("_", 1).to_int()
|
||
numbers[index] = value
|
||
return true
|
||
return false
|
||
|
||
.. code-tab:: csharp
|
||
|
||
[Tool]
|
||
public partial class MyNode : Node
|
||
{
|
||
private int _numberCount;
|
||
|
||
[Export]
|
||
public int NumberCount
|
||
{
|
||
get => _numberCount;
|
||
set
|
||
{
|
||
_numberCount = value;
|
||
_numbers.Resize(_numberCount);
|
||
NotifyPropertyListChanged();
|
||
}
|
||
}
|
||
|
||
private Godot.Collections.Array<int> _numbers = [];
|
||
|
||
public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
|
||
{
|
||
Godot.Collections.Array<Godot.Collections.Dictionary> properties = [];
|
||
|
||
for (int i = 0; i < _numberCount; i++)
|
||
{
|
||
properties.Add(new Godot.Collections.Dictionary()
|
||
{
|
||
{ "name", $"number_{i}" },
|
||
{ "type", (int)Variant.Type.Int },
|
||
{ "hint", (int)PropertyHint.Enum },
|
||
{ "hint_string", "Zero,One,Two,Three,Four,Five" },
|
||
});
|
||
}
|
||
|
||
return properties;
|
||
}
|
||
|
||
public override Variant _Get(StringName property)
|
||
{
|
||
string propertyName = property.ToString();
|
||
if (propertyName.StartsWith("number_"))
|
||
{
|
||
int index = int.Parse(propertyName.Substring("number_".Length));
|
||
return _numbers[index];
|
||
}
|
||
return default;
|
||
}
|
||
|
||
public override bool _Set(StringName property, Variant value)
|
||
{
|
||
string propertyName = property.ToString();
|
||
if (propertyName.StartsWith("number_"))
|
||
{
|
||
int index = int.Parse(propertyName.Substring("number_".Length));
|
||
_numbers[index] = value.As<int>();
|
||
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 :ref:`@GDScript.@export<class_@GDScript_annotation_@export>`, :ref:`@GDScript.@export_enum<class_@GDScript_annotation_@export_enum>`, :ref:`@GDScript.@export_group<class_@GDScript_annotation_@export_group>`, etc. If you want to customize exported properties, use :ref:`_validate_property()<class_Object_private_method__validate_property>`.
|
||
|
||
\ **Note:** If the object's script is not :ref:`@GDScript.@tool<class_@GDScript_annotation_@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.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__init:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **_init**\ (\ ) |virtual| :ref:`🔗<class_Object_private_method__init>`
|
||
|
||
Викликається, коли скрипт об'єкта миттєво, часто після того, як об'єкт ініціюється в пам'яті (через ``Object.new()`` в GDScript, або ``new GodotObject`` в C#). Також можна визначитися з параметрами. Цей метод схожий на конструктора у більшості мов програмування.
|
||
|
||
\ **Примітка:** Якщо :ref:`_init()<class_Object_private_method__init>` визначаються *параметри *, об'єкт з скриптом може бути створений безпосередньо. Якщо будь-які інші засоби (наприклад, :ref:`PackedScene.instantiate()<class_PackedScene_method_instantiate>` або :ref:`Node.duplicate()<class_Node_method_duplicate>`) використовуються, ініціалізація скрипти не буде.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__iter_get:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **_iter_get**\ (\ iter\: :ref:`Variant<class_Variant>`\ ) |virtual| :ref:`🔗<class_Object_private_method__iter_get>`
|
||
|
||
Повертає поточне ітероване значення. ``iter`` зберігає стан ітерації, але на відміну від :ref:`_iter_init()<class_Object_private_method__iter_init>` та :ref:`_iter_next()<class_Object_private_method__iter_next>`, стан має бути доступним лише для читання, тому немає обгортки :ref:`Array<class_Array>`.
|
||
|
||
\ **Порада:** У GDScript ви можете використовувати підтип :ref:`Variant<class_Variant>` як тип повернення для :ref:`_iter_get()<class_Object_private_method__iter_get>`. Вказаний тип буде використано для встановлення типу змінної ітератора в циклах ``for``, що підвищує безпеку типів.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__iter_init:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **_iter_init**\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| :ref:`🔗<class_Object_private_method__iter_init>`
|
||
|
||
Ініціалізує ітератор. ``параметр ітерація`` зберігає стан ітерації. Оскільки GDScript не підтримує передачу аргументів за посиланням, як обгортка використовується масив з одного елемента. Повертає ``true``, доки ітератор не досяг кінця.
|
||
|
||
::
|
||
|
||
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.
|
||
|
||
\ **Примітка:** Або ж ви можете ігнорувати ``параметр`` та використовувати стан об'єкта, див. `онлайн-документація <../tutorials/scripting/gdscript/gdscript_advanced.html#custom-iterators>`__ для прикладу. Зверніть увагу, що в цьому випадку ви не зможете повторно використовувати той самий екземпляр ітератора у вкладених циклах. Також переконайтеся, що ви скинули стан ітератора в цьому методі, якщо хочете використовувати один і той самий екземпляр кілька разів.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__iter_next:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **_iter_next**\ (\ iter\: :ref:`Array<class_Array>`\ ) |virtual| :ref:`🔗<class_Object_private_method__iter_next>`
|
||
|
||
Переміщує ітератор до наступної ітерації. ``iter`` зберігає стан ітерації. Оскільки GDScript не підтримує передачу аргументів за посиланням, одноелементний масив використовується як оболонка. Повертає ``true``, доки ітератор не досяг кінця.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__notification:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **_notification**\ (\ what\: :ref:`int<class_int>`\ ) |virtual| :ref:`🔗<class_Object_private_method__notification>`
|
||
|
||
Called when the object receives a notification, which can be identified in ``what`` by comparing it with a constant. See also :ref:`notification()<class_Object_method_notification>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
func _notification(what):
|
||
if what == NOTIFICATION_PREDELETE:
|
||
print("Goodbye!")
|
||
|
||
.. code-tab:: csharp
|
||
|
||
public override void _Notification(int what)
|
||
{
|
||
if (what == NotificationPredelete)
|
||
{
|
||
GD.Print("Goodbye!");
|
||
}
|
||
}
|
||
|
||
|
||
|
||
\ **Note:** The base **Object** defines a few notifications (:ref:`NOTIFICATION_POSTINITIALIZE<class_Object_constant_NOTIFICATION_POSTINITIALIZE>` and :ref:`NOTIFICATION_PREDELETE<class_Object_constant_NOTIFICATION_PREDELETE>`). Inheriting classes such as :ref:`Node<class_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 :ref:`notification()<class_Object_method_notification>` and varies between different notifications. Most notifications are sent in the forward order (i.e. Object class first, most derived class last).
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__property_can_revert:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **_property_can_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`🔗<class_Object_private_method__property_can_revert>`
|
||
|
||
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 :ref:`_property_get_revert()<class_Object_private_method__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``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__property_get_revert:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **_property_get_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |virtual| :ref:`🔗<class_Object_private_method__property_get_revert>`
|
||
|
||
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:** :ref:`_property_can_revert()<class_Object_private_method__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.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__set:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **_set**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) |virtual| :ref:`🔗<class_Object_private_method__set>`
|
||
|
||
Override this method to customize the behavior of :ref:`set()<class_Object_method_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 :ref:`_get()<class_Object_private_method__get>` and :ref:`_get_property_list()<class_Object_private_method__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 :ref:`@GDScript.@export<class_@GDScript_annotation_@export>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
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 }
|
||
]
|
||
|
||
.. code-tab:: csharp
|
||
|
||
private Godot.Collections.Dictionary _internalData = new Godot.Collections.Dictionary();
|
||
|
||
public override bool _Set(StringName property, Variant value)
|
||
{
|
||
if (property == "FakeProperty")
|
||
{
|
||
// Storing the value in the fake property.
|
||
_internalData["FakeProperty"] = value;
|
||
return true;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
public override Godot.Collections.Array<Godot.Collections.Dictionary> _GetPropertyList()
|
||
{
|
||
return
|
||
[
|
||
new Godot.Collections.Dictionary()
|
||
{
|
||
{ "name", "FakeProperty" },
|
||
{ "type", (int)Variant.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``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__to_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **_to_string**\ (\ ) |virtual| :ref:`🔗<class_Object_private_method__to_string>`
|
||
|
||
Перевизначте цей метод, щоб налаштувати значення, що повертається :ref:`to_string()<class_Object_method_to_string>`, і, отже, представлення об’єкта як :ref:`String<class_String>`.
|
||
|
||
::
|
||
|
||
func _to_string():
|
||
return "Ласкаво просимо до Godot 4!"
|
||
|
||
func _init():
|
||
print(self) # Виводить "Ласкаво просимо до Godot 4!"
|
||
var a = str(self) # a це "Ласкаво просимо до Godot 4!"
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_private_method__validate_property:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **_validate_property**\ (\ property\: :ref:`Dictionary<class_Dictionary>`\ ) |virtual| :ref:`🔗<class_Object_private_method__validate_property>`
|
||
|
||
Перевизначте цей метод, щоб налаштувати наявні властивості. Усі відомості про властивості проходять через цей метод, за винятком властивостей, доданих за допомогою :ref:`_get_property_list()<class_Object_private_method__get_property_list>`. Вміст словника такий самий, як і в :ref:`_get_property_list()<class_Object_private_method__get_property_list>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
@tool
|
||
extends Node
|
||
|
||
@export var is_number_editable: bool:
|
||
set(valve):
|
||
is_number_editable = valve
|
||
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
|
||
|
||
.. code-tab:: csharp
|
||
|
||
[Tool]
|
||
public partial class MyNode : Node
|
||
{
|
||
private bool _isNumberEditable;
|
||
|
||
[Export]
|
||
public bool IsNumberEditable
|
||
{
|
||
get => _isNumberEditable;
|
||
set
|
||
{
|
||
_isNumberEditable = valve;
|
||
NotifyPropertyListChanged();
|
||
}
|
||
}
|
||
|
||
[Export]
|
||
public int Number { get; set; }
|
||
|
||
public override void _ValidateProperty(властивість Godot.Collections.Dictionary)
|
||
{
|
||
if (property["name"].AsStringName() == PropertyName.Number && !IsNumberEditable)
|
||
{
|
||
var usage = property["usage"].As<PropertyUsageFlags>() | PropertyUsageFlags.ReadOnly;
|
||
property["usage"] = (int)usage;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_add_user_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **add_user_signal**\ (\ signal\: :ref:`String<class_String>`, arguments\: :ref:`Array<class_Array>` = []\ ) :ref:`🔗<class_Object_method_add_user_signal>`
|
||
|
||
Додає визначений користувачем сигнал під назвою ``signal``. Необов’язкові аргументи для сигналу можна додати як :ref:`Array<class_Array>` словників, кожен з яких визначає ``ім’я`` :ref:`String<class_String>` і ``тип`` :ref:`int<class_int>` (див. :ref:`Variant.Type<enum_@GlobalScope_Variant.Type>`). Дивіться також :ref:`has_user_signal()<class_Object_method_has_user_signal>` і :ref:`remove_user_signal()<class_Object_method_remove_user_signal>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
add_user_signal("hurt", [
|
||
{ "name": "damage", "type": TYPE_INT },
|
||
{ "name": "source", "type": TYPE_OBJECT }
|
||
])
|
||
|
||
.. code-tab:: csharp
|
||
|
||
AddUserSignal("Hurt",
|
||
[
|
||
new Godot.Collections.Dictionary()
|
||
{
|
||
{ "name", "damage" },
|
||
{ "type", (int)Variant.Type.Int },
|
||
},
|
||
new Godot.Collections.Dictionary()
|
||
{
|
||
{ "name", "source" },
|
||
{ "type", (int)Variant.Type.Object },
|
||
},
|
||
]);
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_call:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **call**\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`🔗<class_Object_method_call>`
|
||
|
||
Викликає метод ``method`` на об'єкті і повертає результат. Цей метод підтримує змінну кількість аргументів, тому параметри можуть бути передані як окремий список коми.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = Node3D.new()
|
||
node.call("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
|
||
[/gdscript]
|
||
[csharp]
|
||
var node = new Node3D();
|
||
node.Call(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
|
||
|
||
|
||
|
||
\ **Примітка:** У C#, ``method`` повинен бути в змії_папір при зверненні до вбудованих методів Godot. За допомогою імен, виставлених в ``MethodName`` класу, щоб уникнути виділення нового :ref:`StringName<class_StringName>` на кожному виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_call_deferred:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **call_deferred**\ (\ method\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`🔗<class_Object_method_call_deferred>`
|
||
|
||
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.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node3D.new()
|
||
node.call_deferred("rotate", Vector3(1.0, 0.0, 0.0), 1.571)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node3D();
|
||
node.CallDeferred(Node3D.MethodName.Rotate, new Vector3(1f, 0f, 0f), 1.571f);
|
||
|
||
|
||
|
||
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 :ref:`Callable.call_deferred()<class_Callable_method_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 :ref:`StringName<class_StringName>` on each call.
|
||
|
||
\ **Note:** If you're looking to delay the function call by a frame, refer to the :ref:`SceneTree.process_frame<class_SceneTree_signal_process_frame>` and :ref:`SceneTree.physics_frame<class_SceneTree_signal_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)
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_callv:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **callv**\ (\ method\: :ref:`StringName<class_StringName>`, arg_array\: :ref:`Array<class_Array>`\ ) :ref:`🔗<class_Object_method_callv>`
|
||
|
||
Викликає метод ``method`` для об’єкта та повертає результат. На відміну від :ref:`call()<class_Object_method_call>`, цей метод очікує, що всі параметри будуть міститися в ``arg_array``.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node3D.new()
|
||
node.callv("rotate", [Vector3(1.0, 0.0, 0.0), 1.571])
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node3D();
|
||
node.Callv(Node3D.MethodName.Rotate, [new Vector3(1f, 0f, 0f), 1.571f]);
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``method`` має бути в snake_case, коли йдеться про вбудовані методи Godot. Надавайте перевагу використанню назв, представлених у класі ``MethodName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_can_translate_messages:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **can_translate_messages**\ (\ ) |const| :ref:`🔗<class_Object_method_can_translate_messages>`
|
||
|
||
Повертає ``true``, якщо об'єкту дозволено перекладати повідомлення за допомогою методів :ref:`tr()<class_Object_method_tr>` та :ref:`tr_n()<class_Object_method_tr_n>`. Див. також :ref:`set_message_translation()<class_Object_method_set_message_translation>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_cancel_free:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **cancel_free**\ (\ ) :ref:`🔗<class_Object_method_cancel_free>`
|
||
|
||
Якщо цей метод називається під час :ref:`NOTIFICATION_PREDELETE<class_Object_constant_NOTIFICATION_PREDELETE>`, цей об'єкт відхилятиметься безкоштовно і буде залишатися виділеним. Це в основному внутрішня функція, яка використовується для обробки помилок, щоб уникнути користувача від безкоштовних об'єктів, коли вони не призначені.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_connect:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **connect**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`, flags\: :ref:`int<class_int>` = 0\ ) :ref:`🔗<class_Object_method_connect>`
|
||
|
||
Connects a ``signal`` by name to a ``callable``. Optional ``flags`` can be also added to configure the connection's behavior (see :ref:`ConnectFlags<enum_Object_ConnectFlags>` constants).
|
||
|
||
A signal can only be connected once to the same :ref:`Callable<class_Callable>`. If the signal is already connected, this method returns :ref:`@GlobalScope.ERR_INVALID_PARAMETER<class_@GlobalScope_constant_ERR_INVALID_PARAMETER>` and generates an error, unless the signal is connected with :ref:`CONNECT_REFERENCE_COUNTED<class_Object_constant_CONNECT_REFERENCE_COUNTED>`. To prevent this, use :ref:`is_connected()<class_Object_method_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 :ref:`Signal.connect()<class_Signal_method_connect>` instead.
|
||
|
||
\ **Note:** This method, and all other signal-related methods, are thread-safe.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_disconnect:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **disconnect**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) :ref:`🔗<class_Object_method_disconnect>`
|
||
|
||
Відключення сигналу ``signal`` за назвою ``callable``. Якщо підключення не існує, генерує помилку. Використовуйте ``method_connected``, щоб переконатися, що підключення існує.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_emit_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Error<enum_@GlobalScope_Error>` **emit_signal**\ (\ signal\: :ref:`StringName<class_StringName>`, ...\ ) |vararg| :ref:`🔗<class_Object_method_emit_signal>`
|
||
|
||
Видає заданий ``сигнал param`` за назвою. Сигнал має існувати, тому це має бути вбудований сигнал цього класу або одного з його успадкованих класів, або сигнал, визначений користувачем (див. :ref:`add_user_signal()<class_Object_method_add_user_signal>`). Цей метод підтримує змінну кількість аргументів, тому параметри можна передавати як список, розділений комами.
|
||
|
||
Повертає :ref:`@GlobalScope.ERR_UNAVAILABLE<class_@GlobalScope_constant_ERR_UNAVAILABLE>`, якщо ``signal`` не існує або параметри недійсні.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
emit_signal("damage", "srowd", 100)
|
||
emit_signal("end game")
|
||
|
||
.. code-tab:: csharp
|
||
|
||
EmitSignal(SignalName.Hit, "srowd", 100);
|
||
EmitSignal(SignalName.GameOver);
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``signal`` має бути в snake_case, коли йдеться про вбудовані сигнали Godot. Надавайте перевагу використанню імен, представлених у класі ``SignalName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_free:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **free**\ (\ ) :ref:`🔗<class_Object_method_free>`
|
||
|
||
Видаляє об'єкт з пам'яті. Попередні посилання на об'єкт стають недійсними, і будь-яка спроба доступу до них призведе до помилки виконання. Перевірка посилань за допомогою методу :ref:`@GlobalScope.is_instance_valid()<class_@GlobalScope_method_is_instance_valid>` поверне ``false``. Це еквівалентно функції ``memdelete`` в GDExtension C++.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_get>`
|
||
|
||
Повертає значення :ref:`Variant<class_Variant>` заданої властивості ``property``. Якщо ``property`` не існує, цей метод повертає ``null``.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node2D.new()
|
||
node.rotation = 1,5
|
||
var a = node.get("rotation") # a дорівнює 1,5
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node2D();
|
||
node.Rotation = 1,5f;
|
||
var a = node.Get(Node2D.PropertyName.Rotation); // a дорівнює 1,5
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``property`` має бути у snake_case, коли йдеться про вбудовані властивості Godot. Надавайте перевагу використанню імен, представлених у класі ``PropertyName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_class:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **get_class**\ (\ ) |const| :ref:`🔗<class_Object_method_get_class>`
|
||
|
||
Повертає назву об'єкта, як :ref:`String<class_String>`. Дивись ще :ref:`is_class()<class_Object_method_is_class>`.
|
||
|
||
\ **Примітка:** Цей метод ігнорує ``class_name`` декларації. Якщо цей скрипт об'єкта визначився ``class_name``, основа, вбудована назва класу повертається замість.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_incoming_connections:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_incoming_connections**\ (\ ) |const| :ref:`🔗<class_Object_method_get_incoming_connections>`
|
||
|
||
Повернення сигналів, отриманих цим об'єктом. Кожен з'єднання представлений як :ref:`Dictionary<class_Dictionary>`, який містить три записи:
|
||
|
||
- ``signal`` - посилання на :ref:`Signal<class_Signal>`;
|
||
|
||
- ``Callable`` - посилання на :ref:`Callable<class_Callable>`;
|
||
|
||
\ ``flags`` є поєднання :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_indexed:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_indexed**\ (\ property_path\: :ref:`NodePath<class_NodePath>`\ ) |const| :ref:`🔗<class_Object_method_get_indexed>`
|
||
|
||
Отримує властивість об’єкта, індексовану заданим ``property_path``. Шлях має бути :ref:`NodePath<class_NodePath>` відносно поточного об’єкта та може використовувати символ двокрапки (``:``) для доступу до вкладених властивостей.
|
||
|
||
\ **Приклади:** ``"position:x"`` або ``"material:next_pass:blend_mode"``.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node2D.new()
|
||
node.position = Vector2(5, -10)
|
||
var a = node.get_indexed("position") # a is Vector2(5, -10)
|
||
var b = node.get_indexed("position:y") # b дорівнює -10
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node2D();
|
||
node.Position = new Vector2(5, -10);
|
||
var a = node.GetIndexed("position"); // a є Vector2(5, -10)
|
||
var b = node.GetIndexed("position:y"); // b дорівнює -10
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``property_path`` має бути у snake_case, коли йдеться про вбудовані властивості Godot. Надавайте перевагу використанню імен, представлених у класі ``PropertyName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
\ **Примітка:** цей метод не підтримує фактичні шляхи до вузлів у :ref:`SceneTree<class_SceneTree>`, лише шляхи підвластивостей. У контексті вузлів замість цього використовуйте :ref:`Node.get_node_and_resource()<class_Node_method_get_node_and_resource>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_instance_id:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_instance_id**\ (\ ) |const| :ref:`🔗<class_Object_method_get_instance_id>`
|
||
|
||
Повертає унікальний ідентифікатор об'єкта. Цей ідентифікатор може бути збережений в :ref:`EncodedObjectAsID<class_EncodedObjectAsID>`, і може бути використаний для отримання цього екземпляра об'єкта з :ref:`@GlobalScope.instance_from_id()<class_@GlobalScope_method_instance_from_id>`.
|
||
|
||
\ **Примітка:** Цей ідентифікатор корисний тільки під час поточного сеансу. Не відповідає подібному об'єкту, якщо ID надсилається через мережу, або завантажується з файлу пізніше.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_meta:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_meta**\ (\ name\: :ref:`StringName<class_StringName>`, default\: :ref:`Variant<class_Variant>` = null\ ) |const| :ref:`🔗<class_Object_method_get_meta>`
|
||
|
||
Повертає значення метаданих об'єкта на задану запис ``name``. Якщо запис не існує, повертає ``default``. Якщо ``default`` є ``null``, також створюється помилка.
|
||
|
||
\ **Note:** Ім'я метаданих повинна бути дійсним ідентифікатором за методом :ref:`StringName.is_valid_identifier()<class_StringName_method_is_valid_identifier>`.
|
||
|
||
\ **Note:** Метадані, які мають назву, починаючи з низу (``_``) вважається редактором. Редактор-тільки метаданих не відображається в Інспекторі і не слід редагувати, хоча це ще можна знайти цим методом.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_meta_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`StringName<class_StringName>`\] **get_meta_list**\ (\ ) |const| :ref:`🔗<class_Object_method_get_meta_list>`
|
||
|
||
Повертає імена записів метаданих об’єкта як :ref:`Array<class_Array>` з :ref:`StringName<class_StringName>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_method_argument_count:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **get_method_argument_count**\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_get_method_argument_count>`
|
||
|
||
Повертаємо кількість аргументів вказаного ``method`` за назвою.
|
||
|
||
\ **Примітка:** У C#, ``method`` повинен бути в змії_кейс при зверненні до вбудованих методів Godot. За допомогою імен, виставлених в ``MethodName`` класу, щоб уникнути виділення нового :ref:`StringName<class_StringName>` на кожному дзвінку.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_method_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_method_list**\ (\ ) |const| :ref:`🔗<class_Object_method_get_method_list>`
|
||
|
||
Повернути методи цього об’єкта та їх підписи як :ref:`Array<class_Array>` словників. Кожен :ref:`Dictionary<class_Dictionary>` містить наступні записи:
|
||
|
||
- ``name`` - назва методу, як :ref:`String<class_String>`;
|
||
|
||
- ``args`` - :ref:`Array<class_Array>` словників, що представляють аргументи;
|
||
|
||
- ``default_args`` - аргументи за замовчуванням як :ref:`Array<class_Array>` варіантів;
|
||
|
||
- ``flags`` - поєднання :ref:`MethodFlags<enum_@GlobalScope_MethodFlags>`;
|
||
|
||
- ``id`` є внутрішнім ідентифікатором методу :ref:`int<class_int>`;
|
||
|
||
- ``return`` є повернутою вартістю, як :ref:`Dictionary<class_Dictionary>`;
|
||
|
||
\ **Примітка:** Ви словники ``args`` і ``return`` відформатовані ідентично результатам :ref:`get_property_list()<class_Object_method_get_property_list>`, хоча не всі записи використовуються.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_property_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_property_list**\ (\ ) |const| :ref:`🔗<class_Object_method_get_property_list>`
|
||
|
||
Повертаємо список майна об’єкта як :ref:`Array<class_Array>` словників. Кожен :ref:`Dictionary<class_Dictionary>` містить наступні записи:
|
||
|
||
- ``name`` - назва майна, як :ref:`String<class_String>`;
|
||
|
||
- ``class_name`` є порожньою :ref:`StringName<class_StringName>`, якщо майно є :ref:`@GlobalScope.TYPE_OBJECT<class_@GlobalScope_constant_TYPE_OBJECT>` і спадок від класу;
|
||
|
||
- ``type`` - тип нерухомості, як :ref:`int<class_int>` (див. ``inum Variant.Type``);
|
||
|
||
- ``hint`` is *how* властиво редагувати (див. :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
|
||
|
||
- ``hint_string`` залежить від натяка (див. :ref:`PropertyHint<enum_@GlobalScope_PropertyHint>`);
|
||
|
||
\ ``usage`` є поєднанням :ref:`PropertyUsageFlags<enum_@GlobalScope_PropertyUsageFlags>`.
|
||
|
||
\ **Примітка:** У GDScript всі члени класу лікуються як властивості. У C# та GDExtension обов’язково слід відмітити учасників класу, які використовують декоратори або атрибут Godot.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_script:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **get_script**\ (\ ) |const| :ref:`🔗<class_Object_method_get_script>`
|
||
|
||
Повертає екземпляр об'єкта, або ``null``, якщо не додано скрипт.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_signal_connection_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_signal_connection_list**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_get_signal_connection_list>`
|
||
|
||
Повертаємо назву :ref:`Array<class_Array>` з'єднань для вказаного ``signal``. Кожен з'єднання представлений як :ref:`Dictionary<class_Dictionary>`, який містить три записи:
|
||
|
||
- ``сигнал`` є посиланням на :ref:`Signal<class_Signal>`;
|
||
|
||
- ``Callable`` - посилання на підключений :ref:`Callable<class_Callable>`;
|
||
|
||
- ``flags`` - це поєднання :ref:`ConnectFlags<enum_Object_ConnectFlags>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_signal_list:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Array<class_Array>`\[:ref:`Dictionary<class_Dictionary>`\] **get_signal_list**\ (\ ) |const| :ref:`🔗<class_Object_method_get_signal_list>`
|
||
|
||
Returns the list of existing signals as an :ref:`Array<class_Array>` of dictionaries.
|
||
|
||
\ **Note:** Due to the implementation, each :ref:`Dictionary<class_Dictionary>` is formatted very similarly to the returned values of :ref:`get_method_list()<class_Object_method_get_method_list>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_get_translation_domain:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`StringName<class_StringName>` **get_translation_domain**\ (\ ) |const| :ref:`🔗<class_Object_method_get_translation_domain>`
|
||
|
||
Повертає назву домену перекладу, який використовується :ref:`tr()<class_Object_method_tr>` і :ref:`tr_n()<class_Object_method_tr_n>`. Дивіться також :ref:`TranslationServer<class_TranslationServer>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_has_connections:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_connections**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_has_connections>`
|
||
|
||
Повертає ``true``, якщо існує будь-яке з’єднання з заданим ім’ям ``signal``.
|
||
|
||
\ **Примітка.** У C# ``signal`` має бути в snake_case, коли йдеться про вбудовані методи Godot. Надавайте перевагу використанню імен, представлених у класі ``SignalName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_has_meta:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_meta**\ (\ name\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_has_meta>`
|
||
|
||
Повертаємо ``true``, якщо запис метаданих з вказаною ``name``. Дивись також :ref:`get_meta()<class_Object_method_get_meta>`, :ref:`set_meta()<class_Object_method_set_meta>` і :ref:`remove_meta()<class_Object_method_remove_meta>`.
|
||
|
||
\ **Примітка:** Назва метаданих повинна бути дійсним ідентифікатором за методом :ref:`StringName.is_valid_identifier()<class_StringName_method_is_valid_identifier>`.
|
||
|
||
\ **Примітка:** Метадані, які мають назву, починаючи з низу (``_``) вважається редактором. Редактор-тільки метаданих не відображається в Інспекторі і не слід редагувати, хоча це ще можна знайти цим методом.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_has_method:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_method**\ (\ method\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_has_method>`
|
||
|
||
Повертаємо ``true``, якщо надана ``method`` ім'я існує в об'єкті.
|
||
|
||
\ **Примітка:** У C#, ``method`` повинен бути в змії_кейс при зверненні до вбудованих методів Godot. За допомогою імен, виставлених в ``MethodName`` класу, щоб уникнути виділення нового :ref:`StringName<class_StringName>` на кожному дзвінку.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_has_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_has_signal>`
|
||
|
||
Повертає ``true``, якщо вказане ім’я ``signal`` існує в об’єкті.
|
||
|
||
\ **Примітка.** У C# ``signal`` має бути в snake_case, коли йдеться про вбудовані сигнали Godot. Надавайте перевагу використанню імен, представлених у класі ``SignalName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_has_user_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **has_user_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_has_user_signal>`
|
||
|
||
Повертаємо ``true``, якщо вказано ім'я користувача ``signal``. Додані тільки сигнали :ref:`add_user_signal()<class_Object_method_add_user_signal>`. Дивись також :ref:`видалення_user_signal()<class_Object_method_видалення_user_signal>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_is_blocking_signals:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_blocking_signals**\ (\ ) |const| :ref:`🔗<class_Object_method_is_blocking_signals>`
|
||
|
||
Повертаємо ``true``, якщо об'єкт блокує свої сигнали від того, що він вдається. Подивитися :ref:`set_block_signals()<class_Object_method_set_block_signals>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_is_class:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_class**\ (\ class\: :ref:`String<class_String>`\ ) |const| :ref:`🔗<class_Object_method_is_class>`
|
||
|
||
Повертає ``true``, якщо об’єкт успадковує заданий ``class``. Дивіться також :ref:`get_class()<class_Object_method_get_class>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var sprite2d = Sprite2D.new()
|
||
sprite2d.is_class("Sprite2D") # Повертає true
|
||
sprite2d.is_class("Вузол") # Повертає true
|
||
sprite2d.is_class("Node3D") # Повертає false
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var sprite2D = new Sprite2D();
|
||
sprite2D.IsClass("Sprite2D"); // Повертає true
|
||
sprite2D.IsClass("Вузол"); // Повертає true
|
||
sprite2D.IsClass("Node3D"); // Повертає false
|
||
|
||
|
||
|
||
\ **Примітка:** цей метод ігнорує оголошення ``class_name`` у сценарії об’єкта.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_is_connected:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_connected**\ (\ signal\: :ref:`StringName<class_StringName>`, callable\: :ref:`Callable<class_Callable>`\ ) |const| :ref:`🔗<class_Object_method_is_connected>`
|
||
|
||
Повертає ``true``, якщо існує зв’язок між вказаною назвою ``signal`` і ``callable``.
|
||
|
||
\ **Примітка.** У C# ``signal`` має бути в snake_case, коли йдеться про вбудовані сигнали Godot. Надавайте перевагу використанню імен, представлених у класі ``SignalName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_is_queued_for_deletion:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_queued_for_deletion**\ (\ ) |const| :ref:`🔗<class_Object_method_is_queued_for_deletion>`
|
||
|
||
Повернення ``true``, якщо метод :ref:`Node.queue_free()<class_Node_method_queue_free>` був викликаний для об'єкта.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_notification:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **notification**\ (\ what\: :ref:`int<class_int>`, reversed\: :ref:`bool<class_bool>` = false\ ) :ref:`🔗<class_Object_method_notification>`
|
||
|
||
Надсилає надане сповіщення ``what`` усім класам, успадкованим об’єктом, ініціюючи виклики :ref:`_notification()<class_Object_private_method__notification>`, починаючи від найвищого предка (клас **Object**) і опускаючись до сценарію об’єкта.
|
||
|
||
Якщо ``reversed`` має значення ``true``, порядок викликів змінюється на зворотний.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
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.
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var player = new Node2D();
|
||
player.SetScript(GD.Load("res://player.gd"));
|
||
|
||
player.Notification(NotificationEnterTree);
|
||
// Порядок викликів GodotObject -> Node -> Node2D -> player.gd.
|
||
|
||
player.Notification(NotificationEnterTree, true);
|
||
// Порядок виклику player.gd -> Node2D -> Node -> GodotObject.
|
||
|
||
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_notify_property_list_changed:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **notify_property_list_changed**\ (\ ) :ref:`🔗<class_Object_method_notify_property_list_changed>`
|
||
|
||
Визначте :ref:`property_list_changed<class_Object_signal_property_list_changed>` сигнал. Це в основному використовується для оновлення редактора, щоб Інспектор і плагіни редактора були належним чином оновлені.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_property_can_revert:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **property_can_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_property_can_revert>`
|
||
|
||
Повертаємо ``true``, якщо надана ``property`` має користувацьке значення за замовчуванням. Використовуйте :ref:`property_get_revert()<class_Object_method_property_get_revert>`, щоб отримати значення за замовчуванням ``property``.
|
||
|
||
\ **Примітка:** Цей метод використовується Inspector dock для відображення значка реверта. Об'єкт повинен здійснювати :ref:`_property_can_revert()<class_Object_private_method__property_can_revert>` для налаштування значення за замовчуванням. Якщо :ref:`_property_can_revert()<class_Object_private_method__property_can_revert>` не реалізовано, цей метод повертає ``false``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_property_get_revert:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Variant<class_Variant>` **property_get_revert**\ (\ property\: :ref:`StringName<class_StringName>`\ ) |const| :ref:`🔗<class_Object_method_property_get_revert>`
|
||
|
||
Повернення замовного значення за замовчуванням вказаного ``property``. Використовуйте :ref:`Property_can_revert()<class_Object_method_Property_can_revert>`, щоб перевірити, чи має значення ``property``.
|
||
|
||
\ **Примітка:** Цей метод використовується Inspector dock для відображення значка реверта. Об'єкт повинен здійснювати :ref:`_property_get_revert()<class_Object_private_method__property_get_revert>` для налаштування значення за замовчуванням. Якщо :ref:`_property_get_revert()<class_Object_private_method__property_get_revert>` не реалізовано, цей метод повертає ``null``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_remove_meta:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **remove_meta**\ (\ name\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_Object_method_remove_meta>`
|
||
|
||
Вилучає заданий запис ``name`` з метаданих об'єкта. :ref:`has_meta()<class_Object_method_has_meta>`, :ref:`get_meta()<class_Object_method_get_meta>` і :ref:`set_meta()<class_Object_method_set_meta>`.
|
||
|
||
\ **Примітка:** Назва метаданих повинна бути дійсним ідентифікатором за методом :ref:`StringName.is_valid_identifier()<class_StringName_method_is_valid_identifier>`.
|
||
|
||
\ **Примітка:** Метадані, які мають назву, починаючи з низу (``_``) вважається редактором. Редактор-тільки метаданих не відображається в Інспекторі і не слід редагувати, хоча це ще можна знайти цим методом.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_remove_user_signal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **remove_user_signal**\ (\ signal\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_Object_method_remove_user_signal>`
|
||
|
||
Видаляє заданий користувацький сигнал ``signal`` з об'єкта. Див. також :ref:`add_user_signal()<class_Object_method_add_user_signal>` та :ref:`has_user_signal()<class_Object_method_has_user_signal>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Object_method_set>`
|
||
|
||
Призначає ``value`` даній ``property``. Якщо властивість не існує або заданий тип ``value`` не збігається, нічого не відбувається.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node2D.new()
|
||
node.set("global_scale", Vector2(8, 2.5))
|
||
print(node.global_scale) # Друк (8.0, 2.5)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node2D();
|
||
node.Set(Node2D.PropertyName.GlobalScale, new Vector2(8, 2.5f));
|
||
GD.Print(node.GlobalScale); // Виводить (8, 2.5)
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``property`` має бути у snake_case, коли йдеться про вбудовані властивості Godot. Надавайте перевагу використанню імен, представлених у класі ``PropertyName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_block_signals:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_block_signals**\ (\ enable\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_Object_method_set_block_signals>`
|
||
|
||
Якщо встановити на ``true``, об'єкт не може випромінювати сигнали. Так, :ref:`emit_signal()<class_Object_method_emit_signal>` і сигнальних з'єднань не будуть працювати, доки він встановлюється на ``false``.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_deferred:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_deferred**\ (\ property\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Object_method_set_deferred>`
|
||
|
||
Призначає ``value`` даній ``property`` у кінці поточного кадру. Це еквівалентно виклику :ref:`set()<class_Object_method_set>` через :ref:`call_deferred()<class_Object_method_call_deferred>`.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node2D.new()
|
||
add_child(node)
|
||
|
||
node.rotation = 1,5
|
||
node.set_deferred("обертання", 3.0)
|
||
print(node.rotation) # Друкує 1.5
|
||
|
||
очікувати get_tree().process_frame
|
||
print(node.rotation) # Друкує 3.0
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node2D();
|
||
node.Rotation = 1,5f;
|
||
node.SetDeferred(Node2D.PropertyName.Rotation, 3f);
|
||
GD.Print(node.Rotation); // Виводить 1.5
|
||
|
||
await ToSignal(GetTree(), SceneTree.SignalName.ProcessFrame);
|
||
GD.Print(node.Rotation); // Друкує 3.0
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``property`` має бути у snake_case, коли йдеться про вбудовані властивості Godot. Надавайте перевагу використанню імен, представлених у класі ``PropertyName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_indexed:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_indexed**\ (\ property_path\: :ref:`NodePath<class_NodePath>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Object_method_set_indexed>`
|
||
|
||
Призначає нове ``value`` властивості, визначеній ``property_path``. Шлях має бути :ref:`NodePath<class_NodePath>` відносно цього об’єкта та може використовувати символ двокрапки (``:``) для доступу до вкладених властивостей.
|
||
|
||
|
||
.. tabs::
|
||
|
||
.. code-tab:: gdscript
|
||
|
||
var node = Node2D.new()
|
||
node.set_indexed("position", Vector2(42, 0))
|
||
node.set_indexed("position:y", -10)
|
||
print(node.position) # Друк (42.0, -10.0)
|
||
|
||
.. code-tab:: csharp
|
||
|
||
var node = new Node2D();
|
||
node.SetIndexed("position", new Vector2(42, 0));
|
||
node.SetIndexed("position:y", -10);
|
||
GD.Print(node.Position); // Друк (42, -10)
|
||
|
||
|
||
|
||
\ **Примітка.** У C# ``property_path`` має бути у snake_case, коли йдеться про вбудовані властивості Godot. Надавайте перевагу використанню імен, представлених у класі ``PropertyName``, щоб уникнути виділення нового :ref:`StringName<class_StringName>` під час кожного виклику.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_message_translation:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_message_translation**\ (\ enable\: :ref:`bool<class_bool>`\ ) :ref:`🔗<class_Object_method_set_message_translation>`
|
||
|
||
Якщо встановлено значення ``true``, дозволяє об'єкту перекладати повідомлення за допомогою методів :ref:`tr()<class_Object_method_tr>` та :ref:`tr_n()<class_Object_method_tr_n>`. Увімкнено за замовчуванням. Див. також метод :ref:`can_translate_messages()<class_Object_method_can_translate_messages>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_meta:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_meta**\ (\ name\: :ref:`StringName<class_StringName>`, value\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Object_method_set_meta>`
|
||
|
||
Додає чи змінює запис ``name`` всередині метаданих об'єкта. ``value`` метаданих може бути будь-яким :ref:`Variant<class_Variant>`, хоча деякі типи не можуть бути серіалізовані.
|
||
|
||
Якщо ``value`` є ``null``, запис буде видалено. Це еквівалент використання :ref:`remove_meta()<class_Object_method_remove_meta>`. Дивитись також :ref:`has_meta()<class_Object_method_has_meta>` і :ref:`get_meta()<class_Object_method_get_meta>`.
|
||
|
||
\ **Примітка:** Ім'я метаданих має бути дійсним ідентифікатором за методом :ref:`StringName.is_valid_identifier()<class_StringName_method_is_valid_identifier>`.
|
||
|
||
\ **Примітка:** Метадані, які мають назву, що починається з нижнього підкреслення (``_``) вважається тільки для редактора. Метадані тільки для редактора не відображаються в інспекторі та не мають редагуватися, хоча ще можуть бути знайдені цим методом.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_script:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_script**\ (\ script\: :ref:`Variant<class_Variant>`\ ) :ref:`🔗<class_Object_method_set_script>`
|
||
|
||
Прикріплюємо ``script`` на об'єкт, і миттєво розраховує його. В результаті називається скрипт :ref:`_init()<class_Object_private_method__init>`. Використовується для розширення функціональності об'єкта.
|
||
|
||
Якщо скрипт вже існує, його екземпляр засвоюється, і його значення і стан втрачені. Побудовані значення нерухомості все ще зберігаються.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_set_translation_domain:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
|void| **set_translation_domain**\ (\ domain\: :ref:`StringName<class_StringName>`\ ) :ref:`🔗<class_Object_method_set_translation_domain>`
|
||
|
||
Встановлює назву домену перекладу, який використовується :ref:`tr()<class_Object_method_tr>` і :ref:`tr_n()<class_Object_method_tr_n>`. Дивіться також :ref:`TranslationServer<class_TranslationServer>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_to_string:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **to_string**\ (\ ) :ref:`🔗<class_Object_method_to_string>`
|
||
|
||
Повертаємо :ref:`String<class_String>`, що представляє об'єкт. За замовчуванням до ``"<ClassName#RID>"``. Override :ref:`_to_string()<class_Object_private_method__to_string>`, щоб налаштувати рядок представлення об'єкта.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_tr:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **tr**\ (\ message\: :ref:`StringName<class_StringName>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`🔗<class_Object_method_tr>`
|
||
|
||
Перекладає ``message``, використовуючи каталоги перекладу, налаштовані в налаштуваннях проекту. Далі можна уточнити, щоб допомогти з перекладом. Зауважте, що більшість :ref:`Control<class_Control>` вузів автоматично переводять свої рядки, тому цей метод в основному корисний для форматованих рядків або настроюється текст.
|
||
|
||
Якщо :ref:`_translate_messages()<class_Object_private_method__translate_messages>` ``false``, або не доступний переклад, цей метод повертає ``message`` без змін. Див. :ref:`set_message_translation()<class_Object_method_set_message_translation>`.
|
||
|
||
Для докладних прикладів див. :doc:`Міжнародні ігри <../tutorials/i18n/internationalizing_games>`.
|
||
|
||
\ **Примітка:** Цей метод не може використовуватися без екземпляра **Object**, оскільки він вимагає методу :ref:`can_translate_msages()<class_Object_method_can_translate_msages>`. Щоб перевести рядки в статичному контексті, скористайтеся :ref:`TranslationServer.translate()<class_TranslationServer_method_translate>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Object_method_tr_n:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`String<class_String>` **tr_n**\ (\ message\: :ref:`StringName<class_StringName>`, plural_message\: :ref:`StringName<class_StringName>`, n\: :ref:`int<class_int>`, context\: :ref:`StringName<class_StringName>` = &""\ ) |const| :ref:`🔗<class_Object_method_tr_n>`
|
||
|
||
Перекладає ``message`` або ``plural_message``, використовуючи каталоги перекладу, налаштовані в налаштуваннях проекту. Далі можна уточнити, щоб допомогти з перекладом.
|
||
|
||
Якщо :ref:`can_translate_messages()<class_Object_method_can_translate_messages>` є ``false``, або немає перекладу, цей метод повертає ``message`` або ``plural_message``, без змін. Див. :ref:`set_message_translation()<class_Object_method_set_message_translation>`.
|
||
|
||
\ ``n`` - номер, або сума, суб'єкт повідомлення. Застосовується системою перекладів для викопування правильної форми для поточної мови.
|
||
|
||
Для докладних прикладів див. :doc:` Локалізація з використанням gettext <../tutorials/i18n/localization_using_gettext>`.
|
||
|
||
\ **Примітка:** Негативний і :ref:`float<class_float>` номери можуть не застосовуватися до деяких підрахованих предметів. Рекомендовано обробляти ці випадки :ref:`tr()<class_Object_method_tr>`.
|
||
|
||
\ **Примітка:** Цей метод не може використовуватися без екземпляра **Object**, оскільки він вимагає методу :ref:`can_translate_msages()<class_Object_method_can_translate_msages>`. Щоб перевести рядки в статичному контексті, скористайтеся ``message TranslationServer.translate_plural``.
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (Зазвичай, цей метод перевизначається користувачем, щоб він мав вплив.)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (Цей метод не має побічних ефектів. Не змінює ніяку змінну екземпляра об'єкта.)`
|
||
.. |vararg| replace:: :abbr:`vararg (Цей метод приймає будь-яке число аргументів після описаних тут.)`
|
||
.. |constructor| replace:: :abbr:`constructor (Цей метод використовується для побудови типів.)`
|
||
.. |static| replace:: :abbr:`static (Цей метод не потребує екземпляра для виклику, його можна викликати безпосередньо за допомогою назви класу.)`
|
||
.. |operator| replace:: :abbr:`operator (Цей метод описує дійсний оператор для взаємодії з цим типом як з лівим операндом.)`
|
||
.. |bitfield| replace:: :abbr:`BitField (Це значення є цілим числом, складеним у вигляді бітової маски з наступних прапорів.)`
|
||
.. |void| replace:: :abbr:`void (Значення не повертається.)`
|