3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Unity: VSCodeでF12の関数ジャンプが使えない場合の解法

Last updated at Posted at 2021-08-10

F12で関数ジャンプできない問題

VSCodeで関数ジャンプをする際に,関数の文字列に対してF12を押すと No definition found for というようなエラーが出て参照できない時がありました.

結構調べて何とか解決方法を見つけたので解説します.

テストした環境

  • Unity 2019.4.24 / 2020.3.10
  • Microsoft VS Code 1.59.0

色々試した結果,バージョン関わらず 小さいプロジェクトの場合は,なぜか F12 でのジャンプはできなさそう. わかる方いたらお知らせください.

解決方法

1. 問題点を探る

まず,VSCodeでエラーを吐いている可能性があるので, View -> Output を押し,OmniSharp Logのタブを選択して,エラーを見ます(バージョンなどによって場所が違うので少し注意)

FnPVSCode.png

すると,自分の場合は以下のように 「.NETFrameworkNETFrameworkv4.7.1 のフレームワークが見つからないのでhttps://aka.ms/msbuild/developerpacks からダウンロードしろ」と言われます.

Error: The reference assemblies for .NETFramework,Version=v4.7.1 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at https://aka.ms/msbuild/developerpacks

2. .NETFrameworkNETFrameworkv4.7.1をダウンロード & インストール

ということで https://aka.ms/msbuild/developerpacks のページで4.7.1と検索し,そこのリンク(自分の場合は,.NETFrameworkNETFrameworkv4.7.1 )のリンクへと行き,「Download .NETFrameworkNETFrameworkv4.7.1 Developer Pack」をクリックしダウンロードしました.

3. プロジェクトやエディタの設定ファイル的なものを削除

VSCodeとUnityを閉じた後,プロジェクトのフォルダにある .vscode/, .csproj, .sln 関連のファイルやフォルダ(UnityやVSCode起動時に勝手に生成される)をとりあえず消し,再度起動をします.

4. Unity Attach Debuggerを選択する

Ctrl + Shift + PUnity Attach Debuggerが選択されているのを確認。選択されてない場合は,「許可する」ボタンが出るので許可をする。

image.png

すると無事に,F12で関数ジャンプができました~

X. これでも解決できない場合

  • プラグイン, 「C#」が入っていることを確認
  • Unityのプロジェクトで Edit > Preferencesを選択し,External ToolsExternal Script EditorVisual Studio Codeになっていることを確認.
  • Unityの Assets > Open C# Project を選択し、VSCodeを開き直す。
  • 一応 .vscode/, .csproj, .sln 関連のファイルなどを逐一削除して確認

VSCodeとUnityの相性どんだけ悪いねん..

余談

Ctrl + Shift + F12 を押すと,以下のようにジャンプはせずに詳細を見ることも可能です.

F12_extra.png

関数ジャンプ後,Alt + - を押すとUndo(Navigate Backwards), Alt + + を押すとRedo(Navigate Forwards) ができます.

参考

最後に

ぜひ、フォローよろしくお願いいたします!

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?