LoginSignup
6
3

More than 5 years have passed since last update.

UnityでWindow向けにVuforiaアプリをビルドしたら画面が真っ暗になった

Last updated at Posted at 2018-12-17

前書き

UnityでWindows向けにVuforiaを使用したアプリをビルドして起動したら
画面が真っ暗で何もできなかった……
→HololensでVuforiaが動くなら、UWPアプリにすれば動くかもしれないから試してみた
という記事です。

目次

  1. 仮説
  2. 環境
  3. Development Buildでエラーの確認
  4. エラー文を読んでみる
  5. UWP向けにビルド
  6. ビルド時にエラー発生
  7. 実行結果
  8. まとめ

仮説

Hololensアプリ(UWP)でVuforiaが動作するのであれば、
通常のWindows機でもUWPアプリにすればVuforiaが使えるのでは?

環境

  • Windows10 Pro
  • Unity 2017.4.16f1
  • Vuforia 7.0.57

Development Buildでエラーの確認

まずは現状のビルドでエラーが出ていないか確認してみましょう。
Script Debuggingをオンにしてエラーが確認できるようにします。
File>Build Settings...を開き、下記2つにチェックを入れ、ビルドして実行してみます。

  • Development Build
  • Script Debugging

BuildSettings20181211.png

すると、真っ黒画面に赤文字でエラー文が出るという恐ろしい画面が出てきます。
TestWindowsVuforia20181211.png

エラー文を読んでみる

読んでみるとは言ったものの、最初の1文で結論が書いてあります。


DllNotFoundException: VuforiaWrapper

要約:VuforiaWrapperというDLLが見つかりませんよ

エラーがわかったところでGoogle先生に対処法を聞いてみますと、以下のポータルサイトが出てきます。

DllNotFoundException: VuforiaWrapper | Vuforia Developer Portal

こちらの公式サポートの回答は以下の通りです。

No. Historically, Vuforia has never supported Windows builds.

However, we have recently announced that we will support Universal Windows Platform apps running on Windows 10 devices, such as Surface Pro table and HoloLens.

要約すると、
過去にWindows Standaloneをサポートしたことはないが、Universal Windows Platformをサポートすることを発表したよ
という感じでしょうか。

2018年も同じ質問があったため、こちらに対するサポートの回答も記載します。

DLL not found for VuforiaWrapper | Vuforia Developer Portal

Standalone Windows applications are not currently supported by Vuforia.

要約:Windows Standaloneは現在サポートされていません。

ということで、今はWindows Standalone向けにアプリを作ることはできなさそうです。

しかしHololensでは動作しているし、1つ目の回答にあるようにUWPアプリにすれば動作するのでは……?
ということで試してみました!

UWP向けにビルド

UWP向けビルドの環境ができていない方は、こちらなどを参考に環境構築を実施してください。
HoloLens開発環境構築(2018/1版)

上記を参考にするとビルドまでできてしまいます!
ここまでできたら、あとは同じ手順でVuforiaのプロジェクトもUWPにビルドしてみましょう!

ビルド時にエラー発生

Windows StandaloneからUniversal Windows Platformにターゲットを切り替え、
いざビルド!

……何やらエラーが発生しました。
TestWindowsVuforia_buildErrorConsole20181212.png

初めのエラーは以下となっています。

Vuforia requires the WSA Capability 'WebCam' to be set. Please set this capability in the Player Settings
Vuforia requires the WSA Capability 'Microphone' to be set. Please set this capability in the Player Settings
Vuforia requires the WSA Capability 'InternetClient' to be set. Please set this capability in the Player Settings

こちらはビルド失敗のエラーとは別ですが触れておきます。

スマホアプリやUWPアプリの開発を行っていた方であればおおよそ推測できそうですが、
権限が設定されていないというエラーのようです。
今回はクラウドターゲットは使用しないため、「WebCam」と「Microphone」のみ、権限を付与します。
Edit>Project Settings>Playerを開き、Inspecter>Publishing Settings内の一番下にある「Capabilities」から
「WebCam」と「Microphone」を探してチェックを入れます。
TestWindowsVuforia_PublishingSettings20181212.png

さて、これで権限の設定はできましたが、先述したようにビルドエラーとは関係ありません。
ということで、2つ目以降のエラーを見てみます。

Assets\Vuforia\Scripts\DefaultInitializationErrorHandler.cs(10,7): error CS0246: The type or namespace name 'Vuforia' could not be found (are you missing a using directive or an assembly reference?)

要約:Vuforiaというnamespaceが見つかりません
StandaloneからUWPに設定を変えたのみでソースは変更していませんので
設定で変わったところがないか確認してみました。

すると
TestWindowsVuforia_XRSettings20181212.png

Vuforia Augmented Reality Supportのチェックが外れている!!!
というのは間違いで、UWPのPlayer Settings内では改めてチェックを入れる必要があります。
※ビルドターゲット毎に共有される設定と共有されない設定があり、今回は共有されていない部分のため起きたエラーです。

では改めてVuforia Augmented Reality Supportにチェックを入れてビルドしてみますと……

ARApp_UWP20181212.png

無事にビルドができたようです!

.slnファイルを開いたら「Release」にしてローカルコンピューターから実行してみましょう!
TestWindowsVuforiaMicrosoftVisualStudio20181212.png

実行結果

無事アプリとして起動できました!
※マーカー画像、モデルはVuforiaのサンプルです。
TestWindowsVuforia20181212.png

まとめ

Windows Standaloneにビルドができないため、応急処置的にUWP向けとしてビルド、
アプリとして実行できるかという実験的なものでした。
しかしStandaloneに比べて手間がとても増えることなどを考えると、
VuforiaさんがStandaloneに対応していただけるととてもありがたいのですが……。
とにかく仮説がうまくいって満足です!

参考サイト

Vuforia
DllNotFoundException: VuforiaWrapper | Vuforia Developer Portal
DLL not found for VuforiaWrapper | Vuforia Developer Portal
Vuforia Engine Supported Versions

UWP環境構築
HoloLens開発環境構築(2018/1版)

6
3
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
6
3