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.

오버라이드 가능한 함수

Godot의 노드 클래스는 매 프레임마다 또는 씬 트리에 들어갈 때와 같은 특정 이벤트에서 노드를 업데이트하기 위해 재정의할 수 있는 가상 함수를 제공합니다.

이 문서에서는 가장 자주 사용하게 될 항목을 소개합니다.

더 보기

내부적으로 이러한 기능은 Godot의 저수준 알림 시스템에 의존합니다. 자세한 내용은 :ref:`doc_godot_notifications`를 참조하세요.

두 가지 함수를 사용하면 클래스 생성자 외에 노드를 초기화하고 가져올 수 있습니다: _enter_tree()_ready().

노드가 씬 트리에 들어가면 활성화되고 엔진이 _enter_tree() 메서드를 호출합니다. 노드의 자식 노드는 아직 활성 씬의 일부가 아닐 수 있습니다. 노드를 씬 트리에서 제거하고 다시 추가할 수 있으므로 이 함수는 노드의 수명 동안 여러 번 호출될 수 있습니다.

대부분의 경우 _ready()``를 대신 사용합니다. 함수는 ``_enter_tree() 이후 노드 수명 동안 한 번만 호출됩니다. ``_ready()``는 모든 자식 노드가 씬 트리에 먼저 들어가도록 보장하므로 ``get_node()``를 안전하게 호출할 수 있습니다.

더 보기

노드 참조를 얻는 방법에 대해 자세히 알아보려면 :ref:`doc_nodes_and_scene_instances`를 읽어보세요.

또 다른 관련 콜백은 ``_exit_tree()``이며, 노드가 씬 트리를 종료하려고 할 때마다 엔진이 호출합니다. 이는 :ref:`노드.remove_child() <class_Node_method_remove_child>`를 호출하거나 노드를 해제하는 경우일 수 있습니다.

# Called every time the node enters the scene tree.
func _enter_tree():
    pass

# Called when both the node and its children have entered the scene tree.
func _ready():
    pass

# Called when the node is about to leave the scene tree, after all its
# children received the _exit_tree() callback.
func _exit_tree():
    pass

두 가지 가상 방법 _process()``_physics_process()``를 사용하면 각각 노드, 모든 프레임 및 모든 물리 프레임을 업데이트할 수 있습니다. 자세한 내용은 전용 문서 :ref:`doc_idle_and_physics_processing`를 읽어보세요.

# Called every frame.
func _process(delta):
    pass

# Called every physics frame.
func _physics_process(delta):
    pass

두 가지 필수 내장 노드 콜백 함수는 노드._unhandled_input()노드._input() <class_Node_private_method__input>`은 개별 입력 이벤트를 수신하고 처리하는 데 사용됩니다. ``_unhandled_input()` 메서드는 _input() 콜백이나 사용자 인터페이스 구성 요소에서 이미 처리되지 않은 모든 키 누름, 마우스 클릭 등을 수신합니다. 일반적으로 게임플레이 입력에 사용하고 싶습니다. _input() 콜백을 사용하면 ``_unhandled_input()``가 입력 이벤트를 가져오기 전에 입력 이벤트를 가로채서 처리할 수 있습니다.

Godot의 입력에 대해 더 자세히 알아보려면 :ref:`입력 섹션 <toc-learn-features-inputs>`을 참조하세요.

# Called once for every event.
func _unhandled_input(event):
    pass

# Called once for every event before _unhandled_input(), allowing you to
# consume some events.
func _input(event):
    pass

:ref:`노드._get_configuration_warnings() <class_Node_private_method__get_configuration_warnings>`과 같은 재정의 가능한 함수가 더 있습니다. 전문화된 노드 유형은 :ref:`CanvasItem._draw() <class_CanvasItem_private_method__draw>`와 같은 더 많은 콜백을 제공하여 프로그래밍 방식으로 그리거나 :ref:`Control._gui_input() <class_Control_private_method__gui_input>`을 사용하여 UI 요소에 대한 클릭 및 입력을 처리합니다.