Building and running from Unity

In the previous chapter, we saw how to create a new project in Unity; import an AR SDK package, such as Vuforia or ARToolkit, into the project; and build a scene with a camera, target image recognition, and virtual object (cube). To summarize, a Unity AR-ready scene, such as the demo scene we built in the previous chapter, should contain the following:

  • A camera with SDK-specific AR components attached
  • A game object representing an image target, with an SDK-specific component identifying the image to use and where to find it
  • Game objects to render when the target is recognized at runtime, parented by the target, and registered to the target's position in the 3D space
  • The scene hierarchy, arranged according to the requirements of the specific SDK, including additional SDK-specific components

We tested our demo scene by running it in the Unity editor and using the webcam attached to the PC to capture the target and show the augmented view. You can readily make fresh changes, fixes, and improvements, and test it again. This is an iterative process as per which we develop apps.

Now we want to test it on the actual target device. We will build the app as a separate executable that runs outside of Unity.

We will configure Build Settings for your target platform. If your platform is a desktop PC or macOS, like the one you're developing with, there's not a lot of extra work. We'll do a build like that now. You can follow along even if it's not your actual target, just for fun.

To build your project, perform the following steps:

  1. Go to File | Build Settings; this will open the Build Settings dialog box, as shown next:

At the top of the dialog is the Scenes In Build list. This should contain the name of the scene you want to include in this build with its checkbox checked. A quick way to add the current scene that is presently open in Editor is using the Add Open Scenes button.

  1. Click on the Add Open Scenes button.

In the preceding case, I had a scene named Test1, which we built earlier. Remove or uncheck all the scenes from the list, except the one you want to build.

Working with Unity, it is often convenient to save your work or experiments in a new scene. You can end up with multiple scenes in your project. When you go to build, be sure to double-check that Scenes In Build refers to the actual scene you want to build.

As shown in the preceding screenshot, in the Platform list, you can see that PC, Mac & Linux Standalone is presently selected, among the other platforms available. (Your list of platforms may vary depending on your Unity version, the components you installed with Unity, and perhaps your authorization licenses.)

Using Vuforia, you cannot build a macOS desktop app. For a Windows 10 desktop with Vuforia, you must switch to the Windows Store platform to build a UWP version of the app.

If you plan to install for Android or another platform, see the following sections of this chapter.

Vuforia does not support desktop apps, only devices with embedded cameras. For Apple products, this means only iPhones and iPads. For Windows, if you want to build it to run on a Windows desktop, you must build for Universal Windows Platform (UWP).

In Unity, you do this by changing platforms from standalone to Windows Store, as follows:

  1. In the Platform list, select Windows Store and click on Switch Platform.
  2. If it asks you to verify anything, just say OK.
  3. Also, choose SDK (on the right-hand side) as Universal 10, as shown in the next screenshot. (If grayed out, you may need to install the missing platform support using the Unity download installer that installed Unity originally on your machine.)
  4. You can leave Target device as Any device or specify PC.

The following screenshot shows Build Settings for Vuforia on a Windows desktop:

Finally, although we won't go there this time, it's worth pointing out the Player Settings... button; it opens the player settings parameters in the inspector. We do not need to change these now, but eventually we will.

  1. To build the executable, click on Build And Run.
  2. You will be prompted for a name and location of the build files. We recommend that you create a new folder in your project root named Build and specify the file or subfolder name under that, as needed.

If the build encounters errors, well, that's a normal part of getting things going. We can't see your screen right now, so I recommend you check Google for answers. Additionally, there's a great community of users at the Unity Answers forum (http://answers.unity3d.com/).

  1. Once the build completes successfully, because we also chose Build And Run, it will start running. You will see an initial Unity run dialog, as shown in the next screenshot. I often check the Windowed checkbox before clicking on Play!
  1. Depending on the AR SDK configuration, you may receive additional prompts before you launch the app itself. The property sheet dialog ahead is for ARToolkit. Unless you want to toy with property values, just accept the defaults and click on OK. (The directive to pop up this dialog is an option you can control from your scene's AR controller video options.)

If all goes well, you will have a standalone build of your AR app running.

  1. Hold your image target in view of the webcam and the computer graphics should appear.

The next sections will cover additional tools and SDK that need to be installed for each of the other target platforms. Jump to the topic section(s) you want.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset