---
title: イベント機能実行順序
product: Unity Editor
version: '6000.0'
latest_version: '7000.0'
status: This page documents version 6000.0. The latest version is 7000.0.
canonical: https://docs.unity.com/ja-jp/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/execution-order
latest_url: https://docs.unity.com/ja-jp/engine/7000.0/manual/scripting/object-oriented-development/managing-update-order/execution-order.md
generated_at: 2026-11-14T04:36:33.242Z
locale: ja-jp
---

# イベント機能実行順序

> Unity のビルトインイベント関数の実行順序を理解し、イベントに反応してゲームのステートを正しい順序で更新できるようにします。

以下の図は、MonoBehaviour スクリプトコンポーネントのライフサイクル中に実行されるイベント関数の実行シーケンスの概要を示しています。可読性のために、チャートの範囲はスクリプトのライフサイクルのキー部分に限定され、コンテキストに応じて内部サブシステムの余分な更新がいくつか提供されます。完全なプレイヤーループは、特定のシステムとサブシステムの更新のより長く複雑なシーケンスで、定義されたデフォルトの順序で次々と実行されます。プレイヤーループ全体とそのすべてのシステムを取得するには、[PlayerLoop API](/engine/6000.0/script-reference/unityengine/lowlevel/playerloop.md) を使用します。また、この API を使用して、システムの削除、独自のシステムの追加、更新順序の変更など、[プレイヤーループシーケンス](/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/player-loop-customizing.md)をカスタマイズすることもできます。

各コールバックの意味と制限の詳細については、[MonoBehaviour](/engine/6000.0/script-reference/unityengine/monobehaviour.md) API リファレンスの「 **メッセージ** 」セクションを参照してください。


**Order of execution for event functions during the lifecycle of a MonoBehaviour script.:**
![](/api/media?file=/engine/6000.0/media/images/monobehaviour_flowchart.svg)

## シーンのロードとアンロードの前##before-scene-load-and-unload

上の図では示されていない [`SceneManager.sceneLoaded`](/engine/6000.0/script-reference/unityengine/scenemanagement/scenemanager/sceneloaded.md) イベントと [`SceneManager.sceneUnloaded`](/engine/6000.0/script-reference/unityengine/scenemanagement/scenemanager/sceneunloaded.md) イベントは、シーンがロードおよびアンロードされたときにコールバックを受け取ることができます。Unity は、`OnEnable`後、ただしシーン内のすべてのオブジェクトの`Start`前に `sceneLoaded` イベントを発生させます。詳細と使用例については、関連する API リファレンス ページを参照してください。

実行フローの一部としてシーンロードを含む図については、「 ドメインとシーンのリロードの[無効化 」](/engine/6000.0/manual/scripting/compilation-and-code-reload/code-reloading-editor/configurable-enter-play-mode-details.md)を参照してください。

## エディター起動時にコードを実行##run-code-on-editor-launch

Unity エディターやランタイムの起動時に、追加のユーザーアクションや MonoBehaviour スクリプトにコードを含める必要なしに、コードの一部を即座に実行できるようにすると便利な場合があります。[静的コンストラクター](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/static-constructors)を持つクラスに [`[InitializeOnLoad]`](/engine/6000.0/script-reference/unityeditor/initializeonloadattribute.md) 属性を適用することで、ユーザーアクションを必要とせずにエディターの起動時にコードを実行できます。または、[`[InitializeOnLoadMethod]`](/engine/6000.0/script-reference/unityeditor/initializeonloadmethodattribute.md) 属性を個々のメソッドに適用できます。詳細と使用例については、これらの属性の API リファレンスを参照してください。

## ランタイム初期化時のコード実行##run-code-on-runtime-intialization

ランタイムアプリケーションの初期化時にコードを実行するには、[`[RuntimeInitializeOnLoadMethodAttribute]`](/engine/6000.0/script-reference/unityengine/runtimeinitializeonloadmethodattribute.md)をメソッドに適用します。[`RunTimeInitializeLoadType`](/engine/6000.0/script-reference/unityengine/runtimeinitializeloadtype.md)属性パラメーターを指定して、プレイヤーループのどこで属性コードを実行するかをコントロールできます。この属性でマークされたメソッドの実行順序の詳細については、API リファレンスの[`RuntimeInitializeOnLoadMethodAttribute`](/engine/6000.0/script-reference/unityengine/runtimeinitializeonloadmethodattribute.md)を参照してください。

## 内部アニメーション更新##internal-animation-update

以下の図は、通常のアニメーション更新ループの実行順序を示し、上の図で **Internal アニメーション更新** というラベルの付いたノードを展開します。


**Order of execution for the regular Animation update loop.:**
![](/api/media?file=/engine/6000.0/media/images/animation-update-sequence.svg)

図に示す以下のアニメーションループコールバックは、[MonoBehaviour](/engine/6000.0/script-reference/unityengine/monobehaviour.md) から派生したスクリプトで呼び出されます。

* [`MonoBehaviour.OnAnimatorMove`](/engine/6000.0/script-reference/unityengine/monobehaviour/onanimatormove.md)
* [`MonoBehaviour.OnAnimatorIK`](/engine/6000.0/script-reference/unityengine/monobehaviour/onanimatorik.md)

追加のアニメーション関連イベント関数は、[`StateMachineBehaviour`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour.md)から派生したスクリプトで呼び出されます。

* [`StateMachineBehaviour.OnStateMachineEnter`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstatemachineenter.md)
* [`StateMachineBehaviour.OnStateMachineExit`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstatemachineexit.md)
* [`StateMachineBehaviour.OnStateEnter`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstateenter.md)
* [`StateMachineBehaviour.OnStateUpdate`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstateupdate.md)
* [`StateMachineBehaviour.OnStateExit`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstateexit.md)
* [`StateMachineBehaviour.OnStateMove`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstatemove.md)
* [`StateMachineBehaviour.OnStateIK`](/engine/6000.0/script-reference/unityengine/statemachinebehaviour/onstateik.md)

図に示されているその他のアニメーション関数は、アニメーションシステムの内部にあり、コンテキスト用に提供されています。これらの関数にはプロファイラーマーカーが関連付けられているため、[プロファイラー](/engine/6000.0/manual/analysis/profiler.md)を使用して、Unity がフレーム内で呼び出すタイミングを確認できます。Unity がこれらの関数を呼び出すタイミングを知ることは、コールたイベント関数がいつ実行されるかを正確に理解するのにヘルプます。アニメーション関数とプロファイラーマーカーの完全な実行順序については、[プロファイラーマーカー](/engine/6000.0/manual/analysis/profiler/markers.md#animation) を参照してください。

## レンダリング##rendering

この実行順序は、[ビルトインレンダーパイプライン](/engine/6000.0/manual/render-pipelines/built-in-render-pipeline.md)にのみ適用されます。[スクリプタブルレンダーパイプライン](/engine/6000.0/manual/render-pipelines/scriptable-render-pipeline-introduction.md)に基づいてレンダリングするパイプラインの実行順序の詳細については、[URP](/engine/6000.0/manual/render-pipelines/universal-render-pipeline/customizing-urp/inject-a-render-pass/custom-pass-injection-points.md) または [HD レンダーパイプライン (HDRP](https://docs.unity3d.com/Packages/com.unity.render-pipelines.high-definition@latest/index.html?subfolder=/manual/rendering-execution-order.html)) のドキュメントの関連セクションを参照してください。レンダリングの直前に作業する場合は、 [application.onBeforeRender](/engine/6000.0/script-reference/unityengine/application/onbeforerender.md) を参照してください。

* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onprecull.md)カメラがシーンをカリングする前に呼び出されます。カリングは、カメラに表示するオブジェクトを決定します。`OnPreCull`はカリングが発生する直前に呼び出されます。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onbecamevisible.md)オブジェクトが任意のカメラに対して表示/非表示になったときに呼び出されます。オブジェクトはいつでも非表示になるため、上のフローチャートには`OnBecameInvisible`は表示されません。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onwillrenderobject.md)オブジェクトが可視の場合、各カメラに対し**て 1 回**呼び出されます。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onprerender.md)カメラがシーンのレンダリングを開始する前に呼び出されます。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onrenderobject.md)すべての通常のシーンレンダリングが完了した後に呼び出されます。この時点で [GL](/engine/6000.0/script-reference/unityengine/gl.md) クラスまたは [Graphics.DrawMeshNow](/engine/6000.0/script-reference/unityengine/graphics/drawmeshnow.md) を使用してカスタムジオメトリを描画できます。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onpostrender.md)カメラがシーンのレンダリングを終了した後に呼び出されます。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/onrenderimage.md)シーンのレンダリングが完了した後に呼び出され、画像のポストプロセスを可能にします。[ポストプロセスエフェクト](/engine/6000.0/manual/post-processing-and-full-screen-effects/overview.md) を参照してください。
* [](/engine/6000.0/script-reference/unityengine/monobehaviour/ongui.md)GUI イベントに反応してフレームごとに複数回呼び出されます。レイアウトと再描画のイベントが最初に処理され、次に各入力イベントのレイアウトとキーボード/マウスイベントが処理されます。
* シーンビューでギズモを描画するために使用[する`OnDrawGizmos`](/engine/6000.0/script-reference/unityengine/monobehaviour/ondrawgizmos.md)。

> **Note:**
>
> [OnPreCull](/engine/6000.0/script-reference/unityengine/camera/onprecull.md)、[OnPreRender](/engine/6000.0/script-reference/unityengine/camera/onprerender.md)、[OnPostRender](/engine/6000.0/script-reference/unityengine/camera/onpostrender.md)、[OnRenderImage](/engine/6000.0/script-reference/unityengine/camera/onrenderimage.md) は Unity ビルトインイベント関数で、MonoBehaviour スクリプトで呼び出されます。ただし、**これらのスクリプトが有効な Camera コンポーネントと同じオブジェクトにアタッチされている場合のみ**。**異なる** オブジェクトにアタッチされた MonoBehaviour の `OnPreCull`、`OnPreRender`、および `OnPostRender` に対して同等のコールバックを受け取る場合は、スクリプトリファレンスの関連ページのコード例に示すように、同等のデリゲート (名前に小文字の`on`が入っていることに注意してください)、[Camera.onPreCull](/engine/6000.0/script-reference/unityengine/camera/onprecull-1.md)、[Camera.onPreRender](/engine/6000.0/script-reference/unityengine/camera/onprerender-1.md)、および [Camera.onPostRender](/engine/6000.0/script-reference/unityengine/camera/onpostrender-1.md) を使用する必要があります。

## コルーチンと非同期タスクの再開##resumption-of-coroutines-and-asynchronous-tasks

中断されたコルーチンは、使用されている yield 命令に応じて、実行シーケンスの異なる時点で再開できます。例えば、[`WaitForEndOfFrame`](/engine/6000.0/script-reference/unityengine/waitforendofframe.md) を使用したコルーチンはフレームの終了時に再開し、[`WaitForFixedUpdate`](/engine/6000.0/script-reference/unityengine/waitforfixedupdate.md) を使用したコルーチンは固定更新ステップの終了時に再開します。詳細については、[コルーチン](/engine/6000.0/manual/scripting/object-oriented-development/coroutines-section/coroutines.md) を参照してください。

通常の .NET タスクと非同期メソッドは、`Update`フェーズで再開します。コルーチンと同様に、Unity のカスタム [`Awaitable`](/engine/6000.0/script-reference/unityengine/awaitable.md) クラスは、待機時に使用するメソッドに応じて異なるタイミングで再開できます。詳細は、「 Awaitable クラスを使用した[非同期プログラミング](/engine/6000.0/manual/scripting/optimization/async-await-support.md) 」を参照してください。

> **Note:**
>
> コルーチンと非同期タスクの再開の間の正確な実行順序は保証されません。Awaitable はグループ化され、待機順に実行されます。

## MonoBehaviour と Entities の組み合わせ##combining-monobehaviours-with-entities

ECS([エンティティ コンポーネント システム](https://docs.unity3d.com/Packages/com.unity.entities@latest/index.html))を使用する場合、UnityはECSシステム グループの更新をプレイヤー更新ループにマージします。

Entities Systemsウィンドウを使用して、プレイヤー ループ全体に関連するECSシステム グループの更新順序を表示できます。詳細については、Entities パッケージのドキュメントの[システムの更新](https://docs.unity3d.com/Packages/com.unity.entities@1.4/manual/systems-update-order.html#update-order-of-systems)順序を参照してください。

## 制限事項##limitations

一般的に、同じイベント機能が異なるGameObjectsオブジェクトに対して実行される順序は、順序が明示的に的に文書化または設定可能な場合を除き、当てにすることはできません。

同じ MonoBehaviour スクリプトの異なるインスタンスに対してイベント機能が呼び出される順序を指定することはできません。例えば、ある MonoBehaviour の `Update` 機能は、その親や子ゲームオブジェクトを含む別のゲームオブジェクト上の同じ MonoBehaviour の `Update` 機能の前後に呼び出されます。

異なる MonoBehaviour スクリプト間の実行順序を設定するには、[スクリプト実行順序](/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/script-execution-order.md) を参照してください。

## 追加リソース##additional-resources

* [イベント機能](/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/event-functions.md)
* [MonoBehaviour](/engine/6000.0/manual/scripting/object-oriented-development/fundamental-unity-types/class-mono-behaviour.md)
* [PlayerLoop APIリファレンス](/engine/6000.0/script-reference/unityengine/lowlevel/playerloop.md)
* [スクリプト実行順序](/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/script-execution-order.md)
