Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
Node
繼承: Object
被繼承: AnimationMixer, AudioStreamPlayer, CanvasItem, CanvasLayer, EditorFileSystem, EditorPlugin, EditorResourcePreview, HTTPRequest, InstancePlaceholder, MissingNode, MultiplayerSpawner, MultiplayerSynchronizer, NavigationAgent2D, NavigationAgent3D, Node3D, ResourcePreloader, ShaderGlobalsOverride, StatusIndicator, Timer, Viewport, WorldEnvironment
所有場景物件的基底類別。
說明
節點是 Godot 的基礎組件。每個節點可被指定為另一個節點的子節點,形成樹狀結構。每個節點可包含任意數量的子節點,但所有兄弟節點(同一父節點的直接子節點)必須具備唯一名稱。
節點組成的樹稱為場景。場景可儲存至磁碟,再實體化加入其他場景。這讓 Godot 專案的架構和資料模型更具彈性。
場景樹:SceneTree 管理目前啟動的節點樹。當節點被加入場景樹時,會收到 NOTIFICATION_ENTER_TREE 通知,並觸發其 _enter_tree() 回呼。子節點一定在父節點之後加入,也就是說父節點的 _enter_tree() 會先於子節點被呼叫。
當所有節點都已加入場景樹時,會收到 NOTIFICATION_READY 通知,對應的 _ready() 回呼會被觸發。對於一組節點,_ready() 會先從子節點開始,再往上到父節點(反向順序)。
這代表節點加入場景樹時,回呼順序為:父節點的 _enter_tree()、子節點的 _enter_tree()、子節點的 _ready(),最後是父節點的 _ready()(整個場景樹遞迴執行)。
處理流程:節點可覆寫「處理」狀態,每個影格都會收到回呼請求進行處理。一般處理(_process(),可用 set_process() 切換)會盡可能快執行,並視影格率而定,因此 delta(秒)會傳入作為參數。物理處理(_physics_process(),可用 set_physics_process() 切換)每秒會固定次數執行(預設 60 次),適用於處理物理相關程式。
節點也可處理輸入事件。若有 _input() 函式,收到輸入時會呼叫它。多數情況下這可能過於頻繁(除非專案很簡單),可使用 _unhandled_input(),只有當事件沒被其他節點(通常是 Control 類 GUI 節點)處理時才會呼叫,確保節點僅收到該屬於它的事件。
為了追蹤場景階層(特別是場景嵌入場景時),可用 owner 屬性為節點設定「擁有者」,記錄誰產生了哪些實體。這在開發編輯器或工具時尤為有用。
最後,當節點被 Object.free() 或 queue_free() 釋放時,會連同所有子節點一併釋放。
群組:節點可加入任意多個群組以便管理,例如可依遊戲需求建立「敵人」或「可收集物」等群組。參見 add_to_group()、is_in_group()、remove_from_group()。你可取得群組內所有節點、遍歷或批次呼叫群組方法(透過 SceneTree)。
節點網路功能:連線到伺服器(或自行架設,見 ENetMultiplayerPeer)後,可利用內建 RPC(遠端程式呼叫)系統進行網路通訊。只需用 rpc() 呼叫方法名稱,即會在本地與所有連線端執行該方法(連線端=用戶端與接受連線之伺服器)。Godot 會用 NodePath 來辨識接收 RPC 呼叫的節點(請確保所有端的節點名稱一致)。亦可參閱高階網路教學與範例。
注意:script 屬性屬於 Object 類,不屬於 Node。它不像大多數屬性那樣公開,但有 setter 與 getter(見 Object.set_script()、Object.get_script())。
教學
屬性
|
||
|
||
|
||
|
||
|
||
|
||
|
||
BitField[ProcessThreadMessages] |
||
|
方法
訊號
child_entered_tree(node: Node) 🔗
當子 node 進入 SceneTree 時發出,通常是因本節點進入樹(見 tree_entered),或呼叫 add_child()。
此訊號會在子節點自己的 NOTIFICATION_ENTER_TREE 與 tree_entered之後發出。
child_exiting_tree(node: Node) 🔗
當子 node 即將離開 SceneTree 時發出,通常是因本節點離開樹(見 tree_exiting),或子 node 被移除或釋放。
收到本訊號時,子 node 仍可於樹中存取。本訊號會在子節點自己的 tree_exiting 與 NOTIFICATION_EXIT_TREE之後發出。
child_order_changed() 🔗
子節點列表異動時發出。包含新增、移動或移除子節點時。
editor_description_changed(node: Node) 🔗
當節點的編輯器描述欄被更動時發出。
editor_state_changed() 🔗
當與編輯器相關的節點屬性變更時發出。僅於編輯器內發射。
ready() 🔗
當節點就緒並執行完 _ready() 後發出。
renamed() 🔗
當節點的 name 於樹中被更改時發出。
當本節點被 node 取代時發出,詳見 replace_by()。
此訊號於 node 已被加入原父節點作為子節點之後,但原所有子節點重新設為 node 的子節點之前發出。
tree_entered() 🔗
當節點進入樹時發出。
本訊號於相關 NOTIFICATION_ENTER_TREE 通知之後發出。
tree_exited() 🔗
當節點離開樹且不再有效時發出。
本訊號於相關 NOTIFICATION_EXIT_TREE 通知之後發出。
tree_exiting() 🔗
當節點即將離開樹時發出,此時節點仍有效。適合在此進行反初始化(如同「解構函式」)。
該訊號於節點的 _exit_tree()之後,且相關 NOTIFICATION_EXIT_TREE之前發出。
列舉
enum ProcessMode: 🔗
ProcessMode PROCESS_MODE_INHERIT = 0
繼承父節點的 process_mode。這是新建立節點的預設值。
ProcessMode PROCESS_MODE_PAUSABLE = 1
Processes when SceneTree.paused is false. This is the inverse of PROCESS_MODE_WHEN_PAUSED, and the default for the root node.
ProcessMode PROCESS_MODE_WHEN_PAUSED = 2
Processes only when SceneTree.paused is true. This is the inverse of PROCESS_MODE_PAUSABLE.
ProcessMode PROCESS_MODE_ALWAYS = 3
Always processes. Keeps processing, ignoring SceneTree.paused. This is the inverse of PROCESS_MODE_DISABLED.
ProcessMode PROCESS_MODE_DISABLED = 4
Never processes. Completely disables processing, ignoring SceneTree.paused. This is the inverse of PROCESS_MODE_ALWAYS.
enum ProcessThreadGroup: 🔗
ProcessThreadGroup PROCESS_THREAD_GROUP_INHERIT = 0
根據第一個(或祖父)非繼承執行緒組模式的父節點處理此節點。詳情請見 process_thread_group。
ProcessThreadGroup PROCESS_THREAD_GROUP_MAIN_THREAD = 1
於主執行緒上處理此節點(以及設為繼承的子節點)。詳情請見 process_thread_group。
ProcessThreadGroup PROCESS_THREAD_GROUP_SUB_THREAD = 2
於子執行緒上處理此節點(以及設為繼承的子節點)。詳情請見 process_thread_group。
flags ProcessThreadMessages: 🔗
ProcessThreadMessages FLAG_PROCESS_THREAD_MESSAGES = 1
允許此節點在呼叫 _process() 前,處理以 call_deferred_thread_group() 建立的執行緒訊息。
ProcessThreadMessages FLAG_PROCESS_THREAD_MESSAGES_PHYSICS = 2
允許此節點在呼叫 _physics_process() 前,處理以 call_deferred_thread_group() 建立的執行緒訊息。
ProcessThreadMessages FLAG_PROCESS_THREAD_MESSAGES_ALL = 3
允許此節點在呼叫 _process() 或 _physics_process() 之前處理以 call_deferred_thread_group() 建立的執行緒訊息。
enum PhysicsInterpolationMode: 🔗
PhysicsInterpolationMode PHYSICS_INTERPOLATION_MODE_INHERIT = 0
繼承父節點的 physics_interpolation_mode。這是新建立節點的預設值。
PhysicsInterpolationMode PHYSICS_INTERPOLATION_MODE_ON = 1
啟用此節點及設為 PHYSICS_INTERPOLATION_MODE_INHERIT 子節點的物理內插。這是根節點的預設值。
PhysicsInterpolationMode PHYSICS_INTERPOLATION_MODE_OFF = 2
停用此節點及設為 PHYSICS_INTERPOLATION_MODE_INHERIT 子節點的物理內插。
enum DuplicateFlags: 🔗
DuplicateFlags DUPLICATE_SIGNALS = 1
Duplicate the node's signal connections that are connected with the Object.CONNECT_PERSIST flag.
DuplicateFlags DUPLICATE_GROUPS = 2
複製節點的群組。
DuplicateFlags DUPLICATE_SCRIPTS = 4
複製節點的腳本(如與 DUPLICATE_USE_INSTANTIATION 一同使用,也會覆蓋複製子節點的腳本)。
DuplicateFlags DUPLICATE_USE_INSTANTIATION = 8
以 PackedScene.instantiate() 進行複製。若節點來自儲存於磁碟的場景,會以 PackedScene.instantiate() 作為複製節點及其子節點的基礎。
DuplicateFlags DUPLICATE_INTERNAL_STATE = 16
Duplicate also non-serializable variables (i.e. without @GlobalScope.PROPERTY_USAGE_STORAGE).
DuplicateFlags DUPLICATE_DEFAULT = 15
Duplicate using default flags. This constant is useful to add or remove a single flag.
# Duplicate non-exported variables.
var dupe = duplicate(DUPLICATE_DEFAULT | DUPLICATE_INTERNAL_STATE)
enum InternalMode: 🔗
InternalMode INTERNAL_MODE_DISABLED = 0
此節點不會設為內部節點。
InternalMode INTERNAL_MODE_FRONT = 1
此節點將被放置於父節點的子節點列表開頭,位於所有非內部兄弟節點之前。
InternalMode INTERNAL_MODE_BACK = 2
此節點將被放置於父節點的子節點列表末尾,位於所有非內部兄弟節點之後。
enum AutoTranslateMode: 🔗
AutoTranslateMode AUTO_TRANSLATE_MODE_INHERIT = 0
繼承父節點的 auto_translate_mode。這是新建立節點的預設值。
AutoTranslateMode AUTO_TRANSLATE_MODE_ALWAYS = 1
永遠自動翻譯。這是 AUTO_TRANSLATE_MODE_DISABLED 的相反,並且是根節點的預設值。
AutoTranslateMode AUTO_TRANSLATE_MODE_DISABLED = 2
Never automatically translate. This is the inverse of AUTO_TRANSLATE_MODE_ALWAYS.
String parsing for translation template generation will be skipped for this node and children that are set to AUTO_TRANSLATE_MODE_INHERIT.
常數
NOTIFICATION_ENTER_TREE = 10 🔗
節點進入 SceneTree 時收到通知。詳見 _enter_tree()。
本通知於相關 tree_entered 訊號之前收到。
NOTIFICATION_EXIT_TREE = 11 🔗
Notification received when the node is about to exit a SceneTree. See _exit_tree().
This notification is received after the related tree_exiting signal.
This notification is sent in reversed order.
NOTIFICATION_MOVED_IN_PARENT = 12 🔗
已棄用: This notification is no longer sent by the engine. Use NOTIFICATION_CHILD_ORDER_CHANGED instead.
NOTIFICATION_READY = 13 🔗
當節點就緒時收到通知。詳見 _ready()。
NOTIFICATION_PAUSED = 14 🔗
節點暫停時收到通知。詳見 process_mode。
NOTIFICATION_UNPAUSED = 15 🔗
節點恢復運作時收到通知。詳見 process_mode。
NOTIFICATION_PHYSICS_PROCESS = 16 🔗
當 is_physics_processing() 回傳 true 時,每個物理影格都會收到通知。詳見 _physics_process()。
NOTIFICATION_PROCESS = 17 🔗
當 is_processing() 回傳 true 時,每個渲染影格都會收到通知。詳見 _process()。
NOTIFICATION_PARENTED = 18 🔗
當本節點被設為其他節點的子節點時收到通知(見 add_child() 及 add_sibling())。
注意:這不代表本節點已進入 SceneTree。
NOTIFICATION_UNPARENTED = 19 🔗
當父節點對本節點呼叫 remove_child() 時收到通知。
注意:這不代表本節點已離開 SceneTree。
NOTIFICATION_SCENE_INSTANTIATED = 20 🔗
僅有新實體化的場景根節點於 PackedScene.instantiate() 完成時才會收到此通知。
NOTIFICATION_DRAG_BEGIN = 21 🔗
拖曳操作開始時收到通知。所有節點都會收到,而非僅被拖曳者。
可透過拖曳有拖曳資料的 Control(見 Control._get_drag_data())或使用 Control.force_drag() 觸發。
請用 Viewport.gui_get_drag_data() 取得拖曳資料。
NOTIFICATION_DRAG_END = 22 🔗
拖曳操作結束時收到通知。
可用 Viewport.gui_is_drag_successful() 檢查拖曳是否成功。
NOTIFICATION_PATH_RENAMED = 23 🔗
當本節點或其祖先節點的 name 被更改時收到通知。當節點從 SceneTree 移除時不會收到此通知。
NOTIFICATION_CHILD_ORDER_CHANGED = 24 🔗
子節點列表異動時收到通知。新增、移動或移除子節點時皆會發出。
NOTIFICATION_INTERNAL_PROCESS = 25 🔗
當 is_processing_internal() 回傳 true 時,每個渲染影格都會收到通知。
NOTIFICATION_INTERNAL_PHYSICS_PROCESS = 26 🔗
當 is_physics_processing_internal() 回傳 true 時,每個物理影格都會收到通知。
NOTIFICATION_POST_ENTER_TREE = 27 🔗
當節點進入樹,即將收到 NOTIFICATION_READY 前會收到此通知。不同於後者,每次進入樹時都會發送,而非只送一次。
NOTIFICATION_DISABLED = 28 🔗
節點被停用時收到通知。詳見 PROCESS_MODE_DISABLED。
NOTIFICATION_ENABLED = 29 🔗
節點停用後再度啟用時收到通知。詳見 PROCESS_MODE_DISABLED。
NOTIFICATION_RESET_PHYSICS_INTERPOLATION = 2001 🔗
當本節點或其祖先節點呼叫 reset_physics_interpolation() 時收到通知。
NOTIFICATION_EDITOR_PRE_SAVE = 9001 🔗
場景包含本節點且將被儲存於編輯器時,會於儲存前收到此通知。此通知僅於 Godot 編輯器中發送,匯出專案不會發生。
NOTIFICATION_EDITOR_POST_SAVE = 9002 🔗
場景包含本節點且儲存於編輯器後,會於儲存後立即收到通知。此通知僅於 Godot 編輯器中發送,匯出專案不會發生。
NOTIFICATION_WM_MOUSE_ENTER = 1002 🔗
滑鼠進入視窗時收到的通知。
已在內嵌視窗、桌面與網頁平臺上實作。
NOTIFICATION_WM_MOUSE_EXIT = 1003 🔗
滑鼠離開視窗時收到的通知。
已在內嵌視窗、桌面與網頁平臺上實作。
NOTIFICATION_WM_WINDOW_FOCUS_IN = 1004 🔗
當節點的上層 Window 獲得焦點時,會收到來自作業系統的通知。這可能是同一個引擎實例下兩個視窗間的焦點切換,或是從作業系統桌面或第三方應用程式切換到遊戲的視窗(此時也會收到 NOTIFICATION_APPLICATION_FOCUS_IN)。
Window 節點獲得焦點時會收到此通知。
NOTIFICATION_WM_WINDOW_FOCUS_OUT = 1005 🔗
當節點的上層 Window 失去焦點時,會收到來自作業系統的通知。這可能是同一個引擎實例下兩個視窗間的焦點切換,或是從遊戲視窗切換到作業系統桌面或第三方應用程式(此時也會收到 NOTIFICATION_APPLICATION_FOCUS_OUT)。
Window 節點失去焦點時會收到此通知。
NOTIFICATION_WM_CLOSE_REQUEST = 1006 🔗
收到來自作業系統的關閉請求通知(例如使用「關閉」按鈕或 Alt + F4 關閉視窗)。
僅於桌面平臺實作。
NOTIFICATION_WM_GO_BACK_REQUEST = 1007 🔗
收到來自作業系統的返回請求通知(例如在 Android 裝置上按下「返回」按鈕)。
僅於 Android 平臺實作。
NOTIFICATION_WM_SIZE_CHANGED = 1008 🔗
當視窗尺寸改變時收到的通知。
注意: 僅有被調整大小的 Window 節點會收到此通知,不會傳遞給子節點。
NOTIFICATION_WM_DPI_CHANGE = 1009 🔗
當螢幕的 DPI 比例發生變更時,會收到來自作業系統的通知。僅於 macOS 平臺實作。
NOTIFICATION_VP_MOUSE_ENTER = 1010 🔗
當滑鼠游標進入 Viewport 的可見區域且未被其他 Control 或 Window 遮擋時收到的通知,前提是其 Viewport.gui_disable_input 為 false,且無論目前是否有焦點。
NOTIFICATION_VP_MOUSE_EXIT = 1011 🔗
當滑鼠游標離開 Viewport 的可見區域且未被其他 Control 或 Window 遮擋時收到的通知,前提是其 Viewport.gui_disable_input 為 false,且無論目前是否有焦點。
NOTIFICATION_WM_POSITION_CHANGED = 1012 🔗
當視窗被移動時收到的通知。
NOTIFICATION_WM_OUTPUT_MAX_LINEAR_VALUE_CHANGED = 1013 🔗
Notification received when the output max linear value returned by Window.get_output_max_linear_value() has changed.
This occurs when HDR output is enabled or disabled and when any HDR output luminance values of the window have changed, such as when the player adjusts their screen brightness setting or moves the window to a different screen.
NOTIFICATION_OS_MEMORY_WARNING = 2009 🔗
當應用程式超出分配的記憶體時,收到來自作業系統的通知。
僅於 iOS 平臺實作。
NOTIFICATION_TRANSLATION_CHANGED = 2010 🔗
當翻譯可能變更時收到的通知。這可能由使用者變更語系、變更 auto_translate_mode,或節點進入場景樹時觸發。可用於即時響應語言變更,例如即時更新 UI 文字。搭配內建翻譯支援(如 Object.tr())時很有用。
注意: 此通知會與 NOTIFICATION_ENTER_TREE 同時收到,所以如果你是在實體化場景時,子節點尚未初始化。你可以用這個通知設定此節點的翻譯、由腳本產生的子節點,或如果要存取在編輯器中加入的子節點,請確保節點已就緒(使用 is_node_ready())。
func _notification(what):
if what == NOTIFICATION_TRANSLATION_CHANGED:
if not is_node_ready():
await ready # 等待就緒訊號
$Label.text = atr("%d Bananas") % banana_counter
NOTIFICATION_WM_ABOUT = 2011 🔗
當收到「關於」資訊請求時,收到來自作業系統的通知。
僅於 macOS 平臺實作。
NOTIFICATION_CRASH = 2012 🔗
當引擎即將當機時,會收到來自 Godot 當機處理器的通知。
僅於桌面平臺且啟用當機處理器時實作。
NOTIFICATION_OS_IME_UPDATE = 2013 🔗
Notification received from the OS when an update of the Input Method Engine occurs (e.g. change of IME cursor position or composition string).
Implemented on desktop and web platforms.
NOTIFICATION_APPLICATION_RESUMED = 2014 🔗
當應用程式從暫停恢復時,從作業系統收到的通知。
僅適用於 Android 與 iOS 平台。
NOTIFICATION_APPLICATION_PAUSED = 2015 🔗
當應用程式被暫停時,從作業系統收到的通知。
僅適用於 Android 與 iOS 平台。
注意:在 iOS 上,這個訊號觸發後,你大約只有 5 秒可以完成相關任務。超過這個限制,iOS 將會直接終止應用程式,而非單純暫停。
NOTIFICATION_APPLICATION_FOCUS_IN = 2016 🔗
當應用程式獲得焦點時,從作業系統收到的通知,即當焦點從作業系統桌面或第三方應用程式切換到 Godot 任一開啟視窗時。
在桌面與行動平台皆有實作。
NOTIFICATION_APPLICATION_FOCUS_OUT = 2017 🔗
當應用程式失去焦點時,從作業系統收到的通知,即當焦點從 Godot 任一開啟視窗切換到作業系統桌面或第三方應用程式時。
在桌面與行動平台皆有實作。
NOTIFICATION_TEXT_SERVER_CHANGED = 2018 🔗
當 TextServer 變更時收到的通知。
NOTIFICATION_APPLICATION_PIP_MODE_ENTERED = 2019 🔗
Notification received when the application enters picture-in-picture mode.
NOTIFICATION_APPLICATION_PIP_MODE_EXITED = 2020 🔗
Notification received when the application exits picture-in-picture mode.
NOTIFICATION_ACCESSIBILITY_UPDATE = 3000 🔗
Notification received when an accessibility information update is required.
NOTIFICATION_ACCESSIBILITY_INVALIDATE = 3001 🔗
Notification received when accessibility elements are invalidated. All node accessibility elements are automatically deleted after receiving this message, therefore all existing references to such elements should be discarded.
屬性說明
AutoTranslateMode auto_translate_mode = 0 🔗
void set_auto_translate_mode(value: AutoTranslateMode)
AutoTranslateMode get_auto_translate_mode()
Defines if any text should automatically change to its translated version depending on the current locale (for nodes such as Label, RichTextLabel, Window, etc.). Also decides if the node's strings should be parsed for translation template generation.
Note: For the root node, auto translate mode can also be set via ProjectSettings.internationalization/rendering/root_node_auto_translate.
String editor_description = "" 🔗
本節點的自訂描述。滑鼠懸停於編輯器的「場景」面板上該節點時,將顯示此描述作為工具提示。
MultiplayerAPI multiplayer 🔗
MultiplayerAPI get_multiplayer()
與本節點關聯的 MultiplayerAPI 執行個體。請參見 SceneTree.get_multiplayer()。
注意:重新命名或移動節點時,MultiplayerAPI 不會自動移至新路徑,需手動更新。
StringName name 🔗
void set_name(value: StringName)
StringName get_name()
節點的名稱。該名稱在同一父節點下必須唯一。若設定為已存在的兄弟節點名稱,該節點會自動重新命名。
注意:更改名稱時,下列字元會被取代為底線:(. : @ / " %)。特別是 @ 保留給自動產生名稱。詳見 String.validate_node_name()。
The owner of this node. The owner must be an ancestor of this node. When packing the owner node in a PackedScene, all the nodes it owns are also saved with it. See also unique_name_in_owner.
Note: In the editor, nodes not owned by the scene root are usually not displayed in the Scene dock, and will not be saved. To prevent this, remember to set the owner after calling add_child().
Note: The owner needs to be the current scene root. See Instancing scenes in the documentation for more information.
PhysicsInterpolationMode physics_interpolation_mode = 0 🔗
void set_physics_interpolation_mode(value: PhysicsInterpolationMode)
PhysicsInterpolationMode get_physics_interpolation_mode()
The physics interpolation mode to use for this node. Only effective if ProjectSettings.physics/common/physics_interpolation or SceneTree.physics_interpolation is true.
By default, nodes inherit the physics interpolation mode from their parent. This property can enable or disable physics interpolation individually for each node, regardless of their parents' physics interpolation mode.
Note: Some node types like VehicleWheel3D have physics interpolation disabled by default, as they rely on their own custom solution.
Note: When teleporting a node to a distant position, it's recommended to temporarily disable interpolation with reset_physics_interpolation() after moving the node. This avoids creating a visual streak between the old and new positions.
ProcessMode process_mode = 0 🔗
void set_process_mode(value: ProcessMode)
ProcessMode get_process_mode()
The node's processing behavior. To check if the node can process in its current mode, use can_process().
int process_physics_priority = 0 🔗
與 process_priority 類似,但用於 NOTIFICATION_PHYSICS_PROCESS、_physics_process() 或 NOTIFICATION_INTERNAL_PHYSICS_PROCESS。
節點執行處理回呼函式(_process()、NOTIFICATION_PROCESS、NOTIFICATION_INTERNAL_PROCESS)的順序。優先值較低的節點會優先呼叫回呼,與樹序無關。
ProcessThreadGroup process_thread_group = 0 🔗
void set_process_thread_group(value: ProcessThreadGroup)
ProcessThreadGroup get_process_thread_group()
設定本節點的處理執行緒群組(即決定是否在主執行緒或子執行緒收 NOTIFICATION_PROCESS、NOTIFICATION_PHYSICS_PROCESS、_process()、_physics_process() 及其內部版本)。
預設為 PROCESS_THREAD_GROUP_INHERIT,表示本節點與父節點同屬一執行緒群組。群組內節點會同步處理,與其他群組分開(由 process_thread_group_order 決定)。若設為 PROCESS_THREAD_GROUP_SUB_THREAD,群組會在子執行緒(非主執行緒)執行;設為 PROCESS_THREAD_GROUP_MAIN_THREAD 則於主執行緒執行。若父祖節點皆為繼承,則屬於預設執行緒群組,於主執行緒處理,順序為 0。
在子執行緒處理時,不可存取群組外大多數節點函式(除錯模式會報錯)。請用 Object.call_deferred()、call_thread_safe()、call_deferred_thread_group() 等方式與主執行緒(或其他群組)溝通。
理解執行緒群組時,任何非 PROCESS_THREAD_GROUP_INHERIT 的節點都會將設為繼承的子孫節點納入其群組,群組內所有節點會同步與其包含它們的節點一同處理。
int process_thread_group_order 🔗
變更處理執行緒群組的順序。數值較小的群組會比數值大的群組先處理。例如:可讓大量節點先於子執行緒處理,之後再由主執行緒的群組收集結果。
BitField[ProcessThreadMessages] process_thread_messages 🔗
void set_process_thread_messages(value: BitField[ProcessThreadMessages])
BitField[ProcessThreadMessages] get_process_thread_messages()
設定目前執行緒群組是否會處理訊息(於執行緒中呼叫 call_deferred_thread_group()),以及是否要於一般處理或物理處理回呼時接收訊息。
若本節點由 PackedScene 檔案實體化,則為原場景的檔案路徑。僅場景根節點包含此資訊。
bool unique_name_in_owner = false 🔗
若為 true,則可從擁有相同 owner 的任何節點或 owner 本身,利用 get_node() 的特殊 %Name 語法存取本節點。
注意:若另一個相同 owner 的節點名稱與本節點相同,該節點將不再能以唯一方式存取。
方法說明
void _enter_tree() virtual 🔗
當節點進入 SceneTree 時被呼叫(例如產生實體、場景切換,或腳本中呼叫 add_child() 之後)。若節點有子節點,會先呼叫自身的 _enter_tree() 回呼,再呼叫子節點的回呼。
對應於 Object._notification() 中的 NOTIFICATION_ENTER_TREE 通知。
void _exit_tree() virtual 🔗
當節點即將離開 SceneTree 時被呼叫(例如釋放、場景切換,或腳本中呼叫 remove_child() 之後)。如果節點有子節點,會在所有子節點離開後最後呼叫自身的 _exit_tree() 回呼。
對應於 Object._notification() 中的 NOTIFICATION_EXIT_TREE 通知,以及 tree_exiting 訊號。若要在節點已經離開活動樹時接收通知,請連接 tree_exited。
PackedStringArray _get_accessibility_configuration_warnings() virtual const 🔗
The elements in the array returned from this method are displayed as warnings in the Scene dock if the script that overrides it is a tool script, and accessibility warnings are enabled in the editor settings.
Returning an empty array produces no warnings.
PackedStringArray _get_configuration_warnings() virtual const 🔗
若覆寫此方法的腳本為 tool 腳本,這個方法回傳陣列中的元素會在「場景」面板顯示為警告。
回傳空陣列則不會顯示警告。
當需要更新這個節點的警告時,請呼叫 update_configuration_warnings()。
@export var energy = 0:
set(value):
energy = value
update_configuration_warnings()
func _get_configuration_warnings():
if energy < 0:
return ["Energy 必須大於等於 0。"]
else:
return []
RID _get_focused_accessibility_element() virtual const 🔗
Called during accessibility information updates to determine the currently focused sub-element, should return a sub-element RID or the value returned by get_accessibility_element().
void _input(event: InputEvent) virtual 🔗
有輸入事件時會被呼叫。輸入事件會沿著節點樹向上傳遞,直到被某節點消耗為止。
只有啟用輸入處理時才會呼叫,如覆寫本方法會自動啟用,也可用 set_process_input() 切換。
若要消耗輸入事件並阻止其繼續傳遞,可呼叫 Viewport.set_input_as_handled()。
遊戲中建議使用 _unhandled_input() 或 _unhandled_key_input(),這樣 GUI 可以優先攔截事件。
注意:僅當節點存在於場景樹中(即不是孤立節點)時才會呼叫本方法。
void _physics_process(delta: float) virtual 🔗
Called once on each physics tick, and allows Nodes to synchronize their logic with physics ticks. delta is the logical time between physics ticks in seconds and is equal to Engine.time_scale / Engine.physics_ticks_per_second.
It is only called if physics processing is enabled for this Node, which is done automatically if this method is overridden, and can be toggled with set_physics_process().
Processing happens in order of process_physics_priority, lower priority values are called first. Nodes with the same priority are processed in tree order, or top to bottom as seen in the editor (also known as pre-order traversal).
Corresponds to the NOTIFICATION_PHYSICS_PROCESS notification in Object._notification().
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
Note: Accumulated delta may diverge from real world seconds.
void _process(delta: float) virtual 🔗
Called on each idle frame, prior to rendering, and after physics ticks have been processed. delta is the time between frames in seconds.
It is only called if processing is enabled for this Node, which is done automatically if this method is overridden, and can be toggled with set_process().
Processing happens in order of process_priority, lower priority values are called first. Nodes with the same priority are processed in tree order, or top to bottom as seen in the editor (also known as pre-order traversal).
Corresponds to the NOTIFICATION_PROCESS notification in Object._notification().
Note: This method is only called if the node is present in the scene tree (i.e. if it's not an orphan).
Note: When the engine is struggling and the frame rate is lowered, delta will increase. When delta is increased, it's capped at a maximum of Engine.time_scale * Engine.max_physics_steps_per_frame / Engine.physics_ticks_per_second. As a result, accumulated delta may not represent real world time.
Note: When --fixed-fps is enabled or the engine is running in Movie Maker mode (see MovieWriter), process delta will always be the same for every frame, regardless of how much time the frame took to render.
Note: Frame delta may be post-processed by OS.delta_smoothing if this is enabled for the project.
void _ready() virtual 🔗
當節點「就緒」時(即自己與所有子節點都已進入場景樹)會被呼叫。若節點有子節點,會先觸發子節點的 _ready() 回呼,然後才是父節點。
對應於 Object._notification() 內的 NOTIFICATION_READY 通知。另可參考變數用的 @onready 標註。
本方法通常用於初始化。若需更早期初始化,可用 Object._init()。另見 _enter_tree()。
注意:每個節點只會被呼叫一次 _ready()。從場景樹移除再重新加入,不會再自動呼叫,可用 request_ready() 於再次加入前手動請求呼叫。
void _shortcut_input(event: InputEvent) virtual 🔗
當 InputEventKey、InputEventShortcut 或 InputEventJoypadButton 尚未被 _input() 或任何 GUI Control 專案消耗時會呼叫。這個方法會在 _unhandled_key_input() 與 _unhandled_input() 之前呼叫。輸入事件會沿樹狀結構向上傳播,直到被節點消耗為止。
只有啟用快捷鍵處理時才會呼叫,覆寫本方法會自動啟用,也可用 set_process_shortcut_input() 切換。
若要消耗輸入事件並阻止其繼續傳遞,可呼叫 Viewport.set_input_as_handled()。
本方法可用於處理快捷鍵。若為一般 GUI 事件,請用 _input();遊戲事件通常適合用 _unhandled_input() 或 _unhandled_key_input() 處理。
注意:僅當節點存在於場景樹中(即不是孤立節點)時才會呼叫本方法。
void _unhandled_input(event: InputEvent) virtual 🔗
當 InputEvent 尚未被 _input() 或任何 GUI Control 專案消耗時會呼叫。這會在 _shortcut_input() 和 _unhandled_key_input() 之後呼叫。輸入事件會沿樹狀結構向上傳播,直到被節點消耗為止。
只有啟用未處理輸入處理時才會呼叫,覆寫本方法會自動啟用,也可用 set_process_unhandled_input() 切換。
若要消耗輸入事件並阻止其繼續傳遞,可呼叫 Viewport.set_input_as_handled()。
對於遊戲輸入,本方法通常比 _input() 更合適,因為 GUI 事件優先度較高。若是鍵盤快捷鍵,請改用 _shortcut_input(),因為它會先被呼叫。若需處理鍵盤事件,建議基於效能考量使用 _unhandled_key_input()。
注意:僅當節點存在於場景樹中(即不是孤立節點)時才會呼叫本方法。
void _unhandled_key_input(event: InputEvent) virtual 🔗
當 InputEventKey 沒有被 _input() 或任何 GUI Control 元件消耗時呼叫。這方法會在 _shortcut_input() 之後,_unhandled_input() 之前呼叫。輸入事件會沿著節點樹向上傳播直到被消耗。
僅當啟用未處理按鍵輸入處理時才會呼叫,覆寫本方法會自動啟用,也可用 set_process_unhandled_key_input() 切換。
要消耗輸入事件並阻止其繼續傳遞,可呼叫 Viewport.set_input_as_handled()。
此方法可用於處理帶有 Alt、Alt + Ctrl、Alt + Shift 修飾鍵的 Unicode 字元輸入(在快捷鍵處理完畢後)。
對於遊戲輸入,這個方法和 _unhandled_input() 通常比 _input() 更適合,因為應先處理 GUI 事件。本方法效能也優於 _unhandled_input(),因為像 InputEventMouseMotion 這類無關事件會自動被過濾。若需處理快捷鍵,請改用 _shortcut_input()。
注意:僅當節點存在於場景樹中(即不是孤立節點)時才會呼叫本方法。
void add_child(node: Node, force_readable_name: bool = false, internal: InternalMode = 0) 🔗
Adds a child node. Nodes can have any number of children, but every child must have a unique name. Child nodes are automatically deleted when the parent node is deleted, so an entire scene can be removed by deleting its topmost node.
If force_readable_name is true, improves the readability of the added node. If not named, the node is renamed to its type, and if it shares name with a sibling, a number is suffixed more appropriately. This operation is very slow. As such, it is recommended leaving this to false, which assigns a dummy name featuring @ in both situations.
If internal is different than INTERNAL_MODE_DISABLED, the child will be added as internal node. These nodes are ignored by methods like get_children(), unless their parameter include_internal is true. It also prevents these nodes being duplicated with their parent. The intended usage is to hide the internal nodes from the user, so the user won't accidentally delete or modify them. Used by some GUI nodes, e.g. ColorPicker.
Note: If node already has a parent, this method will fail. Use remove_child() first to remove node from its current parent. For example:
var child_node = get_child(0)
if child_node.get_parent():
child_node.get_parent().remove_child(child_node)
add_child(child_node)
Node childNode = GetChild(0);
if (childNode.GetParent() != null)
{
childNode.GetParent().RemoveChild(childNode);
}
AddChild(childNode);
If you need the child node to be added below a specific node in the list of children, use add_sibling() instead of this method.
Note: If you want a child to be persisted to a PackedScene, you must set owner in addition to calling add_child(). This is typically relevant for tool scripts and editor plugins. If add_child() is called without setting owner, the newly added Node will not be visible in the scene tree, though it will be visible in the 2D/3D view.
void add_sibling(sibling: Node, force_readable_name: bool = false) 🔗
將 sibling 節點新增到本節點的父節點,並將其放在本節點的下方。
若 force_readable_name 為 true,會提升新增 sibling 的名稱可讀性。若未命名,則 sibling 會以其型別命名;若與其他同級節點有相同 name,則會自動加上合適的數字後綴。此操作非常緩慢,建議將此值保留為 false,此時會自動分配包含 @ 的臨時名稱。
若不需將子節點插入於特定節點下方,請使用 add_child() 取代本方法。
注意:若本節點為內部節點,則所新增的同級節點也會是內部節點(詳見 add_child() 的 internal 參數)。
void add_to_group(group: StringName, persistent: bool = false) 🔗
Adds the node to the group. Groups can be helpful to organize a subset of nodes, for example "enemies" or "collectables". See notes in the description, and the group methods in SceneTree.
If persistent is true, the group will be stored when saved inside a PackedScene. All groups created and displayed in the Groups dock are persistent.
Note: To improve performance, the order of group names is not guaranteed and may vary between project runs. Therefore, do not rely on the group order.
Note: SceneTree's group methods will not work on this node if not inside the tree (see is_inside_tree()).
String atr(message: String, context: StringName = "") const 🔗
利用專案設定中配置的翻譯目錄翻譯 message,可以進一步指定 context 來協助翻譯。大多數 Control 節點會自動翻譯字串,因此本方法主要用於格式化字串或自訂繪製文字。
本方法運作方式與 Object.tr() 相同,但會考慮 auto_translate_mode 狀態。
若 Object.can_translate_messages() 為 false 或無翻譯可用,則會直接返回原始 message。請參見 Object.set_message_translation()。
詳細範例請參閱 國際化遊戲。
String atr_n(message: String, plural_message: StringName, n: int, context: StringName = "") const 🔗
利用專案設定中配置的翻譯目錄翻譯 message 或 plural_message,可進一步指定 context 協助翻譯。
本方法與 Object.tr_n() 相同,但會參考 auto_translate_mode 狀態。
若 Object.can_translate_messages() 為 false 或無翻譯可用,則直接返回 message 或 plural_message。請參見 Object.set_message_translation()。
n 代表主題的數量/數值,翻譯系統會據此取得適用語言的正確複數形式。
詳細範例請參閱 使用 gettext 進行在地化。
注意:負數及 float 型別可能不適用於某些可數主題。建議以 atr() 處理這些情況。
Variant call_deferred_thread_group(method: StringName, ...) vararg 🔗
本函式類似 Object.call_deferred(),但會在節點執行緒組被處理時執行。若節點執行緒組於子執行緒中處理,則會在該執行緒於呼叫 NOTIFICATION_PROCESS、NOTIFICATION_PHYSICS_PROCESS、_process() 或 _physics_process() 或其內部版本之前執行此呼叫。
Variant call_thread_safe(method: StringName, ...) vararg 🔗
本函式能保證無論是否於執行緒中執行皆能成功呼叫。若於不允許呼叫的執行緒中執行,則該呼叫會自動延後。否則會直接呼叫。
bool can_auto_translate() const 🔗
Returns true if this node can automatically translate messages depending on the current locale. See auto_translate_mode, atr(), and atr_n().
若節點可接收處理通知及輸入回呼(如 NOTIFICATION_PROCESS、_input() 等)來自 SceneTree 或 Viewport,則回傳 true。回傳值取決於 process_mode:
設為 PROCESS_MODE_PAUSABLE 時,僅當遊戲執行中(SceneTree.paused 為
false)時回傳true;設為 PROCESS_MODE_WHEN_PAUSED 時,僅當遊戲暫停(SceneTree.paused 為
true)時回傳true;設為 PROCESS_MODE_ALWAYS 時,總是回傳
true;設為 PROCESS_MODE_DISABLED 時,總是回傳
false;設為 PROCESS_MODE_INHERIT 時,則繼承父節點的 process_mode。
若節點不在場景樹中,則無論 process_mode 為何都回傳 false。
建立新的 Tween 並綁定到本節點。
等同於以下操作:
get_tree().create_tween().bind_node(self)
GetTree().CreateTween().BindNode(this);
該 Tween 會在下個處理影格或物理影格自動開始(依 TweenProcessMode 而定)。詳見 Tween.bind_node()。
注意:即使節點未在 SceneTree 內,本方法仍可使用。但若使用自訂 MainLoop,則可能失敗。
Node duplicate(flags: int = 15) const 🔗
Duplicates the node, returning a new node with all of its properties, signals, groups, and children copied from the original, recursively. The behavior can be tweaked through the flags (see DuplicateFlags). Internal nodes are not duplicated.
Note: For nodes with a Script attached, if Object._init() has been defined with required parameters, the duplicated node will not have a Script.
Note: By default, this method will duplicate only properties marked for serialization (i.e. using @GlobalScope.PROPERTY_USAGE_STORAGE, or in GDScript, @GDScript.@export). If you want to duplicate all properties, use DUPLICATE_INTERNAL_STATE.
Node find_child(pattern: String, recursive: bool = true, owned: bool = true) const 🔗
尋找本節點的第一個 name 符合 pattern 的後代節點,若未找到則回傳 null。比對僅針對節點名稱,不比對完整路徑,使用 String.match(),區分大小寫。"*" 代表零個或多個字元,"?" 代表任一字元。
若 recursive 為 false,僅會檢查本節點的直接子節點。節點依樹狀順序檢查,先檢查第一個直接子節點,然後是其子孫,之後才檢查第二個直接子節點。搜尋時也包含內部子節點(見 add_child() 的 internal 參數)。
若 owned 為 true,則僅檢查有有效 owner 的後代。
注意:本方法可能非常緩慢,建議將找到的節點參考儲存於變數。或可考慮以唯一名稱搭配 get_node()(見 unique_name_in_owner)。
注意:若要搜尋所有符合模式或型別的後代節點,請參考 find_children()。
Array[Node] find_children(pattern: String, type: String = "", recursive: bool = true, owned: bool = true) const 🔗
Finds all descendants of this node whose names match pattern, returning an empty Array if no match is found. The matching is done against node names, not their paths, through String.match(). As such, it is case-sensitive, "*" matches zero or more characters, and "?" matches any single character.
If type is not empty, only descendants inheriting from type are included (see Object.is_class()).
If recursive is false, only this node's direct children are checked. Nodes are checked in tree order, so this node's first direct child is checked first, then its own direct children, etc., before moving to the second direct child, and so on. Internal children are also included in the search (see internal parameter in add_child()).
If owned is true, only descendants with a valid owner node are checked.
Note: This method can be very slow. Consider storing references to the found nodes in a variable.
Note: To find a single descendant node matching a pattern, see find_child().
Node find_parent(pattern: String) const 🔗
尋找本節點的第一個 name 符合 pattern 的父節點,若未找到則回傳 null。比對採用 String.match(),區分大小寫。"*" 代表零個或多個字元,"?" 代表任一字元。另見 find_child() 與 find_children()。
注意:此方法會沿場景樹向上搜尋,在大型或深層結構中可能較慢。建議將結果存於變數,或以唯一名稱呼叫 get_node()(參見 unique_name_in_owner)。
RID get_accessibility_element() const 🔗
Returns main accessibility element RID.
Note: This method should be called only during accessibility information updates (NOTIFICATION_ACCESSIBILITY_UPDATE).
Node get_child(idx: int, include_internal: bool = false) const 🔗
Fetches a child node by its index. Each child node has an index relative to its siblings (see get_index()). The first child is at index 0. Negative values can also be used to start from the end of the list. This method can be used in combination with get_child_count() to iterate over this node's children. If no child exists at the given index, this method returns null and an error is generated.
If include_internal is false, internal children are ignored (see add_child()'s internal parameter).
# Assuming the following are children of this node, in order:
# First, Middle, Last.
var a = get_child(0).name # a is "First"
var b = get_child(1).name # b is "Middle"
var b = get_child(2).name # b is "Last"
var c = get_child(-1).name # c is "Last"
Note: To fetch a node by NodePath, use get_node().
int get_child_count(include_internal: bool = false) const 🔗
返回本節點的子節點數量。
若 include_internal 為 false,則不計入內部子節點(詳見 add_child() 的 internal 參數)。
Array[Node] get_children(include_internal: bool = false) const 🔗
返回本節點所有子節點的 Array。
若 include_internal 為 false,則回傳陣列中不包含內部子節點(詳見 add_child() 的 internal 參數)。
Array[StringName] get_groups() const 🔗
返回本節點所屬群組名稱的 Array。
注意:為提升效能,群組名稱順序不保證固定,可能每次專案執行皆不同,請勿依賴其順序。
注意:此方法可能會回傳部分以底線(_)開頭的群組名稱,這些為引擎內部用群組。為避免衝突,請勿以底線作為自訂群組開頭。若要排除內部群組,可參考下列程式片段:
# 僅儲存非內部群組(StringNames 陣列)
var non_internal_groups = []
for group in get_groups():
if not str(group).begins_with("_"):
non_internal_groups.push_back(group)
// 僅儲存非內部群組(StringNames 列表)
List<string> nonInternalGroups = new List<string>();
foreach (string group in GetGroups())
{
if (!group.BeginsWith("_"))
nonInternalGroups.Add(group);
}
int get_index(include_internal: bool = false) const 🔗
返回本節點在同級節點中的順序,第一個節點索引為 0。詳見 get_child()。
若 include_internal 為 false,則返回的索引會忽略內部子節點,第一個非內部子節點索引為 0(詳見 add_child() 的 internal 參數)。
Window get_last_exclusive_window() const 🔗
返回包含本節點的 Window,或從包含該節點的視窗起始之視窗鏈中最近的獨佔子視窗。
int get_multiplayer_authority() const 🔗
返回本節點多人遊戲管理者的對等端 ID。詳見 set_multiplayer_authority()。
Node get_node(path: NodePath) const 🔗
取得節點。 NodePath 可為相對路徑(由本節點出發)或絕對路徑(由 SceneTree.root 出發)。若 path 未指向有效節點,則產生錯誤並回傳 null。若對該返回值呼叫方法,會出現 「嘗試對 null 實例呼叫 <method>。」 錯誤。
注意:以絕對路徑取得節點,僅在節點已進入場景樹時有效(參見 is_inside_tree())。
範例:假設本方法於 Character 節點下呼叫,場景樹如下:
┖╴root
┠╴Character (你在這裡)
┃ ┠╴Sword
┃ ┖╴Backpack
┃ ┖╴Dagger
┠╴MyGame
┖╴Swamp
┠╴Alligator
┠╴Mosquito
┖╴Goblin
以下呼叫將獲得有效節點:
get_node("Sword")
get_node("Backpack/Dagger")
get_node("../Swamp/Alligator")
get_node("/root/MyGame")
GetNode("Sword");
GetNode("Backpack/Dagger");
GetNode("../Swamp/Alligator");
GetNode("/root/MyGame");
Array get_node_and_resource(path: NodePath) 🔗
Fetches a node and its most nested resource as specified by the NodePath's subname. Returns an Array of size 3 where:
Element
0is the Node, ornullif not found;Element
1is the subname's last nested Resource, ornullif not found;Element
2is the remaining NodePath, referring to an existing, non-Resource property (see Object.get_indexed()).
Example: Assume that the child's Sprite2D.texture has been assigned an AtlasTexture:
var a = get_node_and_resource("Area2D/Sprite2D")
print(a[0].name) # Prints Sprite2D
print(a[1]) # Prints <null>
print(a[2]) # Prints ^""
var b = get_node_and_resource("Area2D/Sprite2D:texture:atlas")
print(b[0].name) # Prints Sprite2D
print(b[1].get_class()) # Prints AtlasTexture
print(b[2]) # Prints ^""
var c = get_node_and_resource("Area2D/Sprite2D:texture:atlas:region")
print(c[0].name) # Prints Sprite2D
print(c[1].get_class()) # Prints AtlasTexture
print(c[2]) # Prints ^":region"
var a = GetNodeAndResource(NodePath("Area2D/Sprite2D"));
GD.Print(a[0].Name); // Prints Sprite2D
GD.Print(a[1]); // Prints <null>
GD.Print(a[2]); // Prints ^"
var b = GetNodeAndResource(NodePath("Area2D/Sprite2D:texture:atlas"));
GD.Print(b[0].name); // Prints Sprite2D
GD.Print(b[1].get_class()); // Prints AtlasTexture
GD.Print(b[2]); // Prints ^""
var c = GetNodeAndResource(NodePath("Area2D/Sprite2D:texture:atlas:region"));
GD.Print(c[0].name); // Prints Sprite2D
GD.Print(c[1].get_class()); // Prints AtlasTexture
GD.Print(c[2]); // Prints ^":region"
Node get_node_or_null(path: NodePath) const 🔗
依 NodePath 取得節點。類似 get_node(),但若 path 未指向有效節點時不會產生錯誤。
Variant get_node_rpc_config() const 🔗
Returns a Dictionary mapping method names to their RPC configuration defined for this node using rpc_config().
Note: This method only returns the RPC configuration assigned via rpc_config(). See Script.get_rpc_config() to retrieve the RPCs defined by the Script.
Array[int] get_orphan_node_ids() static 🔗
Returns object IDs of all orphan nodes (nodes outside the SceneTree). Used for debugging.
Note: get_orphan_node_ids() only works in debug builds. When called in a project exported in release mode, get_orphan_node_ids() will return an empty array.
返回本節點的父節點;若無父節點則回傳 null。
傳回節點相對於 SceneTree.root 的絕對路徑。若節點不在場景樹內,則此方法會失敗並傳回空的 NodePath。
NodePath get_path_to(node: Node, use_unique_path: bool = false) const 🔗
傳回從此節點到指定 node 的相對 NodePath。兩個節點必須位於同一個 SceneTree 或場景階層中,否則此方法會失敗並傳回空的 NodePath。
若 use_unique_path 為 true,則會回傳包含此節點唯一名稱的最短路徑(見 unique_name_in_owner)。
注意: 如果你獲得的相對路徑是從唯一節點開始,則此路徑可能會因加上唯一節點的名稱而比一般的相對路徑還長。
float get_physics_process_delta_time() const 🔗
傳回自上次物理回呼以來經過的時間(秒)。這個值等同於 _physics_process() 的 delta 參數,除非變更 Engine.physics_ticks_per_second,否則執行時通常是一致的。另請參閱 NOTIFICATION_PHYSICS_PROCESS。
注意: 若目前畫格率低於 Engine.physics_ticks_per_second / Engine.max_physics_steps_per_frame FPS,回傳值會大於預期。這是為了避免因每格物理步數增加導致效能下降(即所謂的「死亡螺旋」)。這個行為會影響 _process() 與 _physics_process()。因此,請避免用 delta 來計算真實世界的時間。請改用 Time 單例的方法(如 Time.get_ticks_usec())。
float get_process_delta_time() const 🔗
傳回自上次處理回呼以來經過的時間(秒)。這個值等同於 _process() 的 delta 參數,每個畫格可能會不同。另請參閱 NOTIFICATION_PROCESS。
注意: 若目前畫格率低於 Engine.physics_ticks_per_second / Engine.max_physics_steps_per_frame FPS,回傳值會大於預期。這是為了避免因每格物理步數增加導致效能下降(即所謂的「死亡螺旋」)。這個行為會影響 _process() 與 _physics_process()。因此,請避免用 delta 來計算真實世界的時間。請改用 Time 單例的方法(如 Time.get_ticks_usec())。
bool get_scene_instance_load_placeholder() const 🔗
若此節點為實例載入預留位,則傳回 true。請參閱 InstancePlaceholder 及 set_scene_instance_load_placeholder()。
傳回包含此節點的 SceneTree。若此節點不在樹內,則會產生錯誤並傳回 null。另請參閱 is_inside_tree()。
傳回樹狀結構的字串,主要用於除錯。本版本顯示相對於目前節點的路徑,適合複製/貼上至 get_node() 函式,也可用於遊戲 UI/UX。
範例輸出:
TheGame
TheGame/Menu
TheGame/Menu/Label
TheGame/Menu/Camera2D
TheGame/SplashScreen
TheGame/SplashScreen/Camera2D
String get_tree_string_pretty() 🔗
類似於 get_tree_string(),但本方法傳回更圖形化的樹狀結構字串,與場景面板顯示相似,適合檢查大型樹狀結構。
範例輸出:
┖╴TheGame
┠╴Menu
┃ ┠╴Label
┃ ┖╴Camera2D
┖╴SplashScreen
┖╴Camera2D
Viewport get_viewport() const 🔗
若節點在樹內,則傳回最接近的 Viewport 上層節點;否則傳回 null。
傳回包含此節點的 Window。若節點位於主視窗,等同於取得根節點(get_tree().get_root())。
bool has_node(path: NodePath) const 🔗
若 path 指向有效節點則傳回 true。另請參閱 get_node()。
bool has_node_and_resource(path: NodePath) const 🔗
若 path 指向有效節點,且其子名稱為有效 Resource(例如 Area2D/CollisionShape2D:shape),則傳回 true。非 Resource 類型的屬性(如節點或其他 Variant 類型)不予考慮。另請參閱 get_node_and_resource()。
bool is_ancestor_of(node: Node) const 🔗
若給定的 node 為此節點的直接或間接子節點,則傳回 true。
bool is_displayed_folded() const 🔗
若此節點在場景面板中被折疊,則傳回 true。此方法主要供編輯器外掛與工具使用。另請參閱 set_display_folded()。
bool is_editable_instance(node: Node) const 🔗
若 node 針對此節點啟用了可編輯子節點,則傳回 true。此方法主要供編輯器外掛與工具使用。另請參閱 set_editable_instance()。
bool is_greater_than(node: Node) const 🔗
若給定 node 在場景階層中出現於本節點之後,則傳回 true。
bool is_in_group(group: StringName) const 🔗
若此節點已加入指定 group,則傳回 true。詳見 add_to_group()、remove_from_group() 及 SceneTree 的群組方法說明。
若此節點目前位於 SceneTree 中,則傳回 true。另請參閱 get_tree()。
bool is_multiplayer_authority() const 🔗
若本地系統為此節點的多人遊戲權限方,則傳回 true。
若此節點已就緒(即已進入場景樹且所有子節點皆初始化),則傳回 true。
request_ready() 會將其重設為 false。
bool is_part_of_edited_scene() const 🔗
若此節點屬於目前在編輯器中開啟的場景,則傳回 true。
bool is_physics_interpolated() const 🔗
若已為此節點啟用物理內插(見 physics_interpolation_mode),則返回 true。
注意:只有同時啟用此旗標且SceneTree 內啟用了物理內插時,內插才會生效。可用 is_physics_interpolated_and_enabled() 測試。
bool is_physics_interpolated_and_enabled() const 🔗
若已啟用物理內插(見 physics_interpolation_mode)且SceneTree 內也有啟用,則返回 true。
這是 is_physics_interpolated() 的便利版本,會同時檢查全域設定。
請參閱 SceneTree.physics_interpolation 及 ProjectSettings.physics/common/physics_interpolation。
bool is_physics_processing() const 🔗
若啟用物理處理則傳回 true(見 set_physics_process())。
bool is_physics_processing_internal() const 🔗
若啟用內部物理處理則傳回 true(見 set_physics_process_internal())。
若啟用處理則傳回 true(見 set_process())。
bool is_processing_input() const 🔗
若節點正在處理輸入則傳回 true(見 set_process_input())。
bool is_processing_internal() const 🔗
若啟用內部處理則傳回 true(見 set_process_internal())。
bool is_processing_shortcut_input() const 🔗
若節點正在處理快捷鍵則傳回 true(見 set_process_shortcut_input())。
bool is_processing_unhandled_input() const 🔗
若節點正在處理未處理的輸入則傳回 true(見 set_process_unhandled_input())。
bool is_processing_unhandled_key_input() const 🔗
若節點正在處理未處理的按鍵輸入則傳回 true(見 set_process_unhandled_key_input())。
void move_child(child_node: Node, to_index: int) 🔗
將 child_node 移動至指定索引位置。節點索引為其在兄弟節點中的順序,若 to_index 為負數,則從末尾倒數。另請參閱 get_child() 及 get_index()。
注意: 多個引擎回呼(如 _ready()、_process() 等)及透過 propagate_notification() 傳送的通知,處理順序皆受樹狀順序影響。CanvasItem 節點也會依此順序繪製。另請參閱 process_priority。
void notify_deferred_thread_group(what: int) 🔗
類似於 call_deferred_thread_group(),但用於通知。
void notify_thread_safe(what: int) 🔗
類似於 call_thread_safe(),但用於通知。
void print_orphan_nodes() static 🔗
Prints all orphan nodes (nodes outside the SceneTree). Useful for debugging.
Note: This method only works in debug builds. It does nothing in a project exported in release mode.
void print_tree() 🔗
遞迴印出節點及其所有子節點至主控台。節點無需位於樹中。本方法輸出相對於本節點的 NodePath,適合複製/貼上至 get_node()。另請參閱 print_tree_pretty()。
範例輸出:
.
Menu
Menu/Label
Menu/Camera2D
SplashScreen
SplashScreen/Camera2D
void print_tree_pretty() 🔗
遞迴印出節點和其子節點至主控台,無需在樹內。類似於 print_tree(),但圖形化格式類似於編輯器場景面板,適合檢查大型樹狀結構。
範例輸出:
┖╴TheGame
┠╴Menu
┃ ┠╴Label
┃ ┖╴Camera2D
┖╴SplashScreen
┖╴Camera2D
void propagate_call(method: StringName, args: Array = [], parent_first: bool = false) 🔗
遞迴於本節點及其所有子節點上呼叫指定 method,並傳入 args 作為參數。
若 parent_first 為 true,則會先於本節點呼叫,接著再對所有子節點呼叫。若為 false,則會先呼叫子節點上的方法。
void propagate_notification(what: int) 🔗
於本節點及其所有子節點遞迴呼叫 Object.notification(),並傳入 what 參數。
void queue_accessibility_update() 🔗
Queues an accessibility information update for this node.
void queue_free() 🔗
將此節點排程於目前畫格結束時刪除。刪除時,其所有子節點也會一併移除,對該節點及其子節點的所有參考將失效。
和 Object.free() 不同,queue_free 並非立即刪除,於刪除前仍可存取此節點。多次呼叫 queue_free() 亦安全。可用 Object.is_queued_for_deletion() 檢查畫格結束時是否會刪除。
注意: 節點僅會於所有其他延遲呼叫結束後才釋放。此方式與用 Object.call_deferred() 執行 Object.free() 不全然相同。
void remove_child(node: Node) 🔗
移除子節點 node。該節點及其所有子節點不會被刪除,如需刪除請參閱 queue_free()。
注意:當本節點位於樹內時,如果被移除的 node(或其後代)的 owner 不再是祖先,則此方法會將其 owner 設為 null(見 is_ancestor_of())。
void remove_from_group(group: StringName) 🔗
將節點自指定 group 移除。若節點不在該群組則無動作。詳見說明及 SceneTree 的群組方法。
void reparent(new_parent: Node, keep_global_transform: bool = true) 🔗
Changes the parent of this Node to the new_parent. The node needs to already have a parent. The node's owner is preserved if its owner is still reachable from the new location (i.e., the node is still a descendant of the new parent after the operation).
If keep_global_transform is true, the node's global transform will be preserved if supported. Node2D, Node3D and Control support this argument (but Control keeps only position).
Warning: If ProjectSettings.physics/common/physics_interpolation is enabled and reparenting causes a large change in global transform, the object may appear to move from its old position to its new one over the next physics tick. To avoid this, call reset_physics_interpolation() after reparenting.
void replace_by(node: Node, keep_groups: bool = false) 🔗
以給定的 node 取代本節點。本節點的所有子節點皆會移動到 node。
若 keep_groups 為 true,則 node 會加入被取代節點所在的所有群組(見 add_to_group())。
警告: 被取代節點會自樹中移除,但不會自動刪除。為避免記憶體外洩,請將其儲存於變數或用 Object.free() 釋放。
void request_ready() 🔗
要求下次節點進入樹時再次呼叫 _ready()。不會立即呼叫 _ready()。
注意: 此方法僅影響目前節點。如需讓其子節點也重新呼叫 ready,必須對每個子節點分別呼叫。當節點及其子節點再次進入樹時, _ready() 的呼叫順序與一般情況相同。
void reset_physics_interpolation() 🔗
啟用物理內插時,若將節點移動到截然不同的位置(如場景中重新擺放物件),可能會產生物件從舊位置到新位置的可見異常。
可呼叫本方法暫時停用內插,直到物理步驟完成以避免此現象。
節點及其所有子節點會遞迴收到 NOTIFICATION_RESET_PHYSICS_INTERPOLATION 通知。
注意:本函式應於移動節點之後呼叫,而非之前。
Error rpc(method: StringName, ...) vararg 🔗
將指定 method 的遠端程序呼叫請求發送給網路上的對等端(及本地端),可傳送額外參數給 RPC 所呼叫的方法。只有具有相同 NodePath(包含完全相同 name)的節點會收到此呼叫。行為取決於該方法的 RPC 設定(見 rpc_config() 及 @GDScript.@rpc)。預設情況下,方法不會對 RPC 開放。
成功時回傳 @GlobalScope.OK,若參數不符則回傳 @GlobalScope.ERR_INVALID_PARAMETER,若無法取得 multiplayer(例如節點不在樹內)則回傳 @GlobalScope.ERR_UNCONFIGURED,若連線不可用則回傳 @GlobalScope.ERR_CONNECTION_ERROR。
注意: 僅於收到 MultiplayerAPI 的 MultiplayerAPI.connected_to_server 訊號後,才能安全於客戶端使用 RPC。你也需追蹤連線狀態,可透過 MultiplayerAPI 的訊號(如 MultiplayerAPI.server_disconnected)或檢查 get_multiplayer().peer.get_connection_status() == CONNECTION_CONNECTED。
void rpc_config(method: StringName, config: Variant) 🔗
更改指定 method 的 RPC 設定。config 可設為 null 以停用(預設),或為包含以下項目的 Dictionary:
rpc_mode:見 RPCMode;transfer_mode:見 TransferMode;call_local:若設為true,方法也會在本地呼叫;channel:指定傳送 RPC 的頻道 int。
注意: 在 GDScript,這對應於 @GDScript.@rpc 標註,可接受不同參數(如 @rpc(any)、@rpc(authority)...)。另請參考 高階多人連線 教學。
Error rpc_id(peer_id: int, method: StringName, ...) vararg 🔗
將 rpc() 呼叫發送給指定 peer_id 的對等端(見 MultiplayerPeer.set_target_peer())。
成功時回傳 @GlobalScope.OK,若參數不符則回傳 @GlobalScope.ERR_INVALID_PARAMETER,若無法取得節點 multiplayer(如節點不在樹內)則回傳 @GlobalScope.ERR_UNCONFIGURED,若連線不可用則回傳 @GlobalScope.ERR_CONNECTION_ERROR。
void set_deferred_thread_group(property: StringName, value: Variant) 🔗
類似於 call_deferred_thread_group(),但用於設定屬性。
void set_display_folded(fold: bool) 🔗
若設為 true,此節點將於場景面板中顯示為折疊狀態,其所有子節點亦會隱藏。此方法主要供編輯器外掛與工具使用,但於發行版亦可用。另請參閱 is_displayed_folded()。
void set_editable_instance(node: Node, is_editable: bool) 🔗
設為 true 時,允許 node 擁有的所有節點在場景面板中可用且可編輯,即使其 owner 不是場景根節點。此方法主要供編輯器外掛與工具使用,但於發行版亦可用。另請參閱 is_editable_instance()。
void set_multiplayer_authority(id: int, recursive: bool = true) 🔗
將此節點的多人遊戲權限設為指定對等端(peer)ID 的對等端。多人遊戲權限是指在網路上對此節點具有權限的對等端。預設為對等端 ID 1(伺服器)。可與 rpc_config() 及 MultiplayerAPI 搭配使用。
若 recursive 為 true,則會遞迴地將此權限設定為本節點所有子節點。
警告:這個操作不會自動將新權限同步給其他對等端,需由開發者自行處理。你可以用 MultiplayerSpawner.spawn_function、RPC 或 MultiplayerSynchronizer 來傳遞新權限資訊。此外,父節點的權限不會自動傳遞給新加入的子節點。
void set_physics_process(enable: bool) 🔗
若設為 true,則啟用物理(固定更新率)處理。當節點處於處理狀態時,會以固定間隔(通常為 60 FPS,可透過 Engine.physics_ticks_per_second 更改)收到 NOTIFICATION_PHYSICS_PROCESS,並在有 _physics_process() 回呼時呼叫之。
注意:若有覆寫 _physics_process(),此狀態會在 _ready() 被呼叫前自動啟用。
void set_physics_process_internal(enable: bool) 🔗
若設為 true,則啟用本節點的內部物理處理。內部物理處理獨立於一般的 _physics_process() 呼叫,部分節點會用於確保即使節點暫停或腳本已關閉物理處理(set_physics_process())時依然能正常運作。
警告:內建節點仰賴這種內部邏輯運作,停用後可能會造成非預期行為。請確定你明白用途才操作。
void set_process(enable: bool) 🔗
若設為 true,則啟用處理。當節點被處理時,每個繪製影格都會收到 NOTIFICATION_PROCESS(若有,則呼叫 _process() 回呼)。
注意:若有覆寫 _process(),此狀態會在 _ready() 被呼叫前自動啟用。
注意:這個方法僅影響 _process() 回呼,不會影響像 _physics_process() 這類其他回呼。若欲完全停用節點的所有處理,請將 process_mode 設為 PROCESS_MODE_DISABLED。
void set_process_input(enable: bool) 🔗
若設為 true,則啟用輸入處理。
注意:若有覆寫 _input(),此狀態會在 _ready() 被呼叫前自動啟用。對於像 Button、TextEdit 等 GUI 控制元件,輸入處理預設已啟用。
void set_process_internal(enable: bool) 🔗
若設為 true,則啟用本節點的內部處理。內部處理獨立於一般的 _process() 呼叫,部分節點會用於確保即使節點暫停或因腳本停用處理(set_process())時依然能正常運作。
警告:內建節點仰賴這種內部邏輯運作,停用後可能會造成非預期行為。請確定你明白用途才操作。
void set_process_shortcut_input(enable: bool) 🔗
若設為 true,則啟用本節點的快捷鍵處理。
注意:若有覆寫 _shortcut_input(),此狀態會在 _ready() 被呼叫前自動啟用。
void set_process_unhandled_input(enable: bool) 🔗
若設為 true,則啟用未處理輸入的處理。這會讓節點收到所有尚未被處理的輸入(通常由 Control 類元件處理)。
注意:若有覆寫 _unhandled_input(),此狀態會在 _ready() 被呼叫前自動啟用。未處理輸入對於 Button、TextEdit 等 GUI 控制元件已預設啟用。
void set_process_unhandled_key_input(enable: bool) 🔗
若設為 true,則啟用未處理鍵盤輸入的處理。
注意:若有覆寫 _unhandled_key_input(),此狀態會在 _ready() 被呼叫前自動啟用。
void set_scene_instance_load_placeholder(load_placeholder: bool) 🔗
If set to true, the node becomes an InstancePlaceholder when packed and instantiated from a PackedScene. See also get_scene_instance_load_placeholder().
void set_thread_safe(property: StringName, value: Variant) 🔗
類似於 call_thread_safe(),但用於設定屬性。
void set_translation_domain_inherited() 🔗
使本節點繼承其父節點的翻譯網域。若本節點沒有父節點,則會使用主要翻譯網域。
這是所有節點的預設行為。如呼叫 Object.set_translation_domain() 會停用此行為。
void update_configuration_warnings() 🔗
刷新在「場景」面板中為本節點顯示的警告。可用 _get_configuration_warnings() 自訂要顯示的警告訊息。