Unity は、ゲームやエディタープロセスのフォレンジックデバッグやライブデバッグのために、Windows 上でデバッグするためのいくつかのオプションを提供します。Unity では、ネイティブの C++ デバッグと C# マネージデバッグの 2 種類のデバッグが可能です。
Windows デバッガー (WinDbg) で Unity サーバー URL にアクセスするには Unity の シンボルストア を使います。または、Visual Studio 2019 以降は、シンボルの自動解決とダウンロードに対応しています。
.sympath
コマンドを使用すると、簡単に WinDbg にシンボルストアを加えることができます。
.sympath+ SRV*c:\\symbols-cache*http://symbolserver.unity3d.com/
上のパスで
.sympath+
プラス (+) は既存のシンボルパスを保持し、シンボルストアを追加します。
SRV*c:\\symbols-cache
SRV はフェッチ元のリモートサーバーを示します。一方、c:\\symbols
はローカルパスで、ダウンロードされたシンボルをキャッシュし、再度ダウンロードする前に最初にそこを参照します。
*http://symbolserver.unity3d.com/
フェッチ元のシンボルストアのパスです。
Visual Studio をデバッグ用に設定するには、以下の手順に従います。 1. Tools > Options を選択します。 2. Debugging セクションを開き、Symbols を選択します。 3. キャッシュディレクトリが指定されていない場合は、指定します。 4. Unity の シンボルストア など、シンボルファイル (.pdb) の場所 を追加します。
Live デバッギングは、すでに実行中の処理や、例外をキャッチした場所にデバッガーを接続する想定です。デバッガ―が状態を把握するために、Visual Studio の設定 セクションで説明する手順を使用して、シンボルをビルド内に加える必要があります。さらに、ゲームの実行可能ファイルの名前がゲーム名と同じである場合 (特に名前が変更された実行可能ファイルにアクセスできない場合)、デバッガーが正しい .pdb
ファイルを見つけるのに問題が発生する可能性があります。
Windows では、アプリケーションクラッシュが自動的に Dr Watson/Error Reporting に送信され Microsoft に報告されるように設定されています。ただし、Visual Studio か WinDbg がインストールされている場合は、かわりに クラッシュのデバッグ を選択できるオプションが Microsoft によって提供されています。
このレジストリファイルのコンテンツに従ってインストールします。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug]
"Auto"="1"
[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug]
"Auto"="1"
エディターデバッグのための追加コンテンツです。
Unity.exe -dbgbreak
自動クラッシュ処理が設定されている場合、上記は Unity を起動して、すばやくデバッガーを接続します。
Windows にはクラッシュダンプファイル (.dmp または .mdmp) を調査する機能があります。クラッシュダンプによっては、スタック情報または処理メモリ全体が表示されます。ダンプファイルのコンテンツからクラッシュの原因を特定します。通常、少なくとも、含まれているスタック (有効なスタックである限り) が調査されます。
ダンプファイルを調査するには、Visual Studio または WinDbg を使ってそれをロードします。Visual Studio は操作が簡単です。一方、WinDbg は追加機能があるので、デバッグツールとして好まれています。
Visual Studio を実行する場合、Unity による VS Code 用の UnityMixedCallstack 拡張を使用すると、デバッグをさらに簡単に行うことができます。
NullReferenceException
は、通常は以下のようになります。
1b45558c()
> mono-2.0-bdwgc.dll!malloc(unsigned int size=12) Line 163 + 0x5f bytes C
mono-2.0-bdwgc.dll!g_hash_table_insert_replace(_GHashTable * hash=0x065c3960, void * key=0x0018cba4, void * value=0x0018cb8c, int replace=457528232) Line 204 + 0x7 bytes C
mono-2.0-bdwgc.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes C
マネージスタックフレームは、通常以下ような形になります。
1b45558c()
> mono-2.0-bdwgc.dll!malloc(unsigned int size=12) Line 163 + 0x5f bytes C
mono-2.0-bdwgc.dll!g_hash_table_insert_replace(_GHashTable * hash=0x065c3960, void * key=0x0018cba4, void * value=0x0018cb8c, int replace=457528232) Line 204 + 0x7 bytes C
mono-2.0-bdwgc.dll!mono_jit_runtime_invoke(_MonoMethod * method=0x242bf8b0, void * obj=0x065c3960, void ** params=0x0018cba4, MonoObject * * exc=0x0018cb8c) Line 4889 + 0xc bytes C
何も情報がない行は、マネージフレームです。mono でマネージスタック情報を取得するには、mono_pmip
というビルトイン関数を使用します。この関数は、スタック フレームのアドレスを受け取り、情報とともに char* を返します。 デバッグのために Visual Studio のイミディエイトウィンドウで mono_pmip
を呼び出すことができます。
?(char*){,,mono-2.0-bdwgc.dll}mono_pmip((void*)0x1b45558c)
0x26a296c0 “ Tiles:OnPostRender () + 0x1e4 (1B4553A8 1B4555DC) [065C6BD0 - Unity Child Domain]”`
ノート: mono-2.0-bdwgc.dll
シンボルが適切にロードされている場合にのみ作動します。
デバッガーが接続されているにもかかわらずアプリケーションがクラッシュしない場合や、デバッガーが利用できないリモートデバイスでクラッシュする場合があります。このような場合、以下の手順でダンプファイルから有用な情報を得ることができます。
ノート: これらの手順は、Windows スタンドアロンとユニバーサル Windows プラットフォームがデスクトップで実行されている場合に適用できます。
HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\Windows Error Reporting
へ移動します。LocalDumps
フォルダーがない場合は作成します。"DumpFolder"=<FolderPath goes here> , e.g., C:\\Temp
"DumpCount"=dword:00000010
"DumpType"=dword:00000002
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.