デフォルトでは、Reload Scene (シーンの再ロード) は有効になっています。つまり、再生モードに入ると、Unity は既存のシーンゲームオブジェクトをすべて破棄し、ディスクからシーンを再ロードします。Unity がこれを行うのにかかる時間は、シーンが複雑になるほど長くなります。つまり、プロジェクトが複雑になるほど、再生ボタンを押してからエディターにシーンが完全に読み込まれるまでの待ち時間は長くなります。
シーンの再ロードを無効にすると、処理時間が短縮されます。これにより、プロジェクトの開発をより速く繰り返すことができます。ディスクからシーンを再ロードする代わりに、シーンの変更されたコンテンツのみがリセットされます。これにより、シーンのアンロードと再ロードによる時間とパフォーマンスへの影響を回避できます。Unity はまだ、あたかも新しくロードされたように、同じ初期化関数 (OnEnable
、OnDisable
、OnDestroy
など) を呼び出します。
Reload Scene を無効にするには、以下を行います。
詳しくは、Play Mode の設定方法 を参照してください。
Reload Scene を無効にすると、エディターでアプリケーションを起動するのにかかる時間は、ビルドされたバージョンの起動時間を表すものではなくなります。したがって、プロジェクトの起動時に何が起こっているのかを正確にデバッグまたはプロファイルしたい場合は、Reload Scene を有効にして、ビルドされたバージョンで発生する実際のロード時間とプロセスをより正確に表す必要があります。
Reload Scene を無効にしても、プロジェクトへの副作用はほとんどありません。ただし、Reload Scene は Reload Domain と密接に関連しているため、いくつかの重要な違いがあります。
ビルドにシリアル化されていない ScriptableObject と MonoBehaviour のフィールド (NonSerialized
、private、internal) は、その値を維持します。これは、Unity が既存のオブジェクトを再作成せず、コンストラクターも呼び出さないためです。さらに、Unityは、配列/List 型の null の private と internal フィールドを、ドメイン再ロード時に空の配列/List オブジェクトに変換し、ランタイム (エディター以外) のスクリプトでも null でない状態を維持します。
ExecuteInEditMode
または ExecuteAlways
スクリプトを使用するスクリプトは、OnDestroy
または Awake
の呼び出しを受けません。Unity は Awake を呼び出さず、OnEnable を呼び出すのは、Awake/OnEnable メソッド (EditorApplication.isPlaying
プロパティを確認します) による再生モードの変更時に、EditorApplication.isPlaying
が既に true である場合のみです。ランタイム(エディターではなく)スクリプトのシリアル化されていないフィールドは編集モードではアクティブではないため、問題ありませんが、ExecuteInEditMode
または ExecuteAlways
でマークされたスクリプトは、自体を変更したり、他のランタイムスクリプトのフィールドに影響したりする可能性があります。これを回避するには、OnEnable コールバックの影響を受けるフィールドを独自に初期化します。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.