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...
オーバーライド可能な関数
Godot の Node クラスは、フレームごと、またはシーンツリーに入ったときなどの特定のイベントごとにノードを更新するためにオーバーライドできる仮想関数を提供します。
このドキュメントでは、最も頻繁に使用するものを紹介します。
参考
内部では、これらの関数はGodotの低レベルの通知システムに依存しています。詳しくは :ref:`doc_godot_notifications`を参照してください。
クラスのコンストラクターの他に、 _enter_tree() と _ready() という 2 つの関数を使用すると、ノードの初期化および取得ができます。
ノードは、シーンツリーに入るとアクティブになり、エンジンはその ``_enter_tree()``メソッドを呼び出します。そのノードの子は、まだアクティブなシーンの一部ではないことがあります。また、シーンツリーへのノードの削除と再追加が可能なため、この関数はノードのライフタイムを通して複数回呼び出される可能性があります。
ほとんどの場合、代わりに _ready() を使用します。この関数はノードの存続期間中に _enter_tree() の後に 1 回だけ呼び出されます。 _ready() は、すべての子が最初にシーンツリーに入っていることを保証するので、それらに対して安全に get_node() を呼び出すことができます。
参考
ノードの参照取得について詳しくは、ビジュアルシェーダー を参照してください。
もう 1 つの関連するコールバックは _exit_tree() です。これはノードがシーンツリーから出るたびにエンジンによって呼び出されます。これは Node.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
// Called every time the node enters the scene tree.
public override void _EnterTree()
{
base._EnterTree();
}
// Called when both the node and its children have entered the scene tree.
public override void _Ready()
{
base._Ready();
}
// Called when the node is about to leave the scene tree, after all its
// children.
public override void _ExitTree()
{
base._ExitTree();
}
仮想関数 _process() と _physics_process() はそれぞれノードを、フレーム毎、物理フレーム毎に更新することができます。詳しくは、専用のドキュメント : アイドル処理と物理処理 を参照してください。
# Called every frame.
func _process(delta):
pass
# Called every physics frame.
func _physics_process(delta):
pass
public override void _Process(double delta)
{
// Called every frame.
base._Process(delta);
}
public override void _PhysicsProcess(double delta)
{
// Called every physics frame.
base._PhysicsProcess(delta);
}
さらに重要な2つの組み込みノードコールバック関数が Node._unhandled_input() と Node._input() です。これらは個々の入力イベントを受信して処理するために使用されます。 _unhandled_input() メソッドは、 _input() コールバックやユーザーインターフェースコンポーネントでまだ処理されていない、すべてのキーの押下、マウスクリックなどを受信します。これは、ゲームプレイの入力全般に使用されます。 _input() コールバックは、 _unhandled_input() が取得する前に入力イベントをインターセプトして処理することを可能にします。
Godotにおける入力の詳細については、 Input section を参照してください。
# 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
// Called once for every event.
public override void _UnhandledInput(InputEvent @event)
{
base._UnhandledInput(@event);
}
// Called once for every event before _UnhandledInput(), allowing you to
// consume some events.
public override void _Input(InputEvent @event)
{
base._Input(@event);
}
仮想関数は、 Node._get_configuration_warnings() など他にもいくつかあります。特殊なノードタイプは、プログラムによる描画を行う CanvasItem._draw() や UI 要素のクリックや入力を処理する Control._gui_input() などのコールバックを提供します。