Unity Quickstart

This guide explains how to import Poly assets using the Poly Toolkit for Unity.

Set up your development environment

Create a project

In Unity, select File > New Project.

Name your project HelloPoly, leave 3D mode selected, and click Create Project.

If you are using Unity 2018.1 or above, you must enable unsafe code (Poly Toolkit uses unsafe { ... } code blocks in C# for performance reasons). To do this:

  1. Click File > Build Settings...,
  2. Click Player Settings to bring up the Player Settings tab.
  3. Find the Allow 'unsafe' code setting (under the Other Settings category) and enable it.

Click the menu Assets > Import package > Custom package..., then select the poly-toolkit-v*.unitypackage file you downloaded. Import everything in the package.

The Poly Asset Browser window opens automatically after installation. You can also open this window by selecting Poly > Browse assets from the menu.

Import at edit time

To import assets at edit time, use the Poly Asset Browser window (available by selecting Poly > Browse assets from the menu).

Use the interface to find an asset either by searching for keywords or browsing by categories. After you locate an asset, review the Import Options (shown below) and click Import into Project to import it as a Prefab.

To instantiate a GameObject, find the prefab in the Project Window (in the folder Assets/Poly/Assets) and drag it to your scene.

Import at run time

The Poly Toolkit includes an example called HelloPoly (located in Assets/PolyToolkit/ExampleScenes) that demonstrates how to import an asset at runtime with the Poly Toolkit API.

This section describes how to run the example.

Get an API key

Get an API key

  • If you aren't already signed in, you'll be asked to sign in with a Google account or create one.

  • In the dialog box, either select an existing API Console project or create a new project

  • Click Next to enable the Poly API and receive your API key. The API key is used to identify your app and enforce usage limits.

You can also create, view, and manage your projects, APIs, and API keys at the Google APIs Console.

Run the example

  1. Enter the API key. In Unity menu, select Poly > Poly Toolkit Settings. The Poly Toolkit settings (shown below) will appear in the Inspector window. If it does not appear, make sure the inspector window is already visible. Then, select the Runtime section, and paste your API key.

  2. Open the scene. In the Project window, find and open the HelloPoly.unity scene in Assets/PolyToolkit/ExamplesScenes.

  3. Now run the project by pressing the Play button in Unity.

After a small delay while the example queries the Poly API, you should see a model of a piano at the center of the scene.

Next Steps

To learn more about using the Poly Toolkit, see the Poly Toolkit Guide.

Troubleshooting

Common import issues

If you see errors after importing Poly Toolkit, check if they correspond to one of the common cases below:

  • Auto-updating obsolete APIs: If you are using Unity 2017 or newer, you may be prompted to automatically upgrade API calls. In this case, make a backup of your project, then click the button labeled "I made a backup. Go ahead." to automatically upgrade Poly Toolkit for compatibility with your version of Unity.

  • Compilation errors due to the unsafe keyword: Some combinations of Unity version and C# compiler don't allow unsafe blocks in C# code by default, and these blocks are required by Poly Toolkit for performance reasons. If you see compilation errors related unsafe blocks, create the files csc.rsp, mcs.rsp and smcs.rsp in your Assets folder with each file containing the single line -unsafe (note the leading dash). This tells the compiler to allow unsafe blocks in code.

Mobile build issues

If your project is configured to build using the IL2CPP script backend (default for mobile platforms like iOS), make sure that you have .NET 2.0 selected as your API compatibility level in Player Settings. The default, .NET 2.0 Subset, is incompatible with Poly Toolkit and may cause runtime errors.