This guide explains how to import Poly assets using the Poly Toolkit for Unity.
Set up your development environment
Install Unity 5.6.3 or later.
Download the latest Poly Toolkit for Unity from the Releases page.
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:
- Click File > Build Settings...,
- Click Player Settings to bring up the Player Settings tab.
- 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..
Run the example
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.
Open the scene. In the Project window, find and open the
HelloPoly.unityscene in
Assets/PolyToolkit/ExamplesScenes.
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
unsafekeyword: Some combinations of Unity version and C# compiler don't allow
unsafeblocks in C# code by default, and these blocks are required by Poly Toolkit for performance reasons. If you see compilation errors related
unsafeblocks, create the files
csc.rsp,
mcs.rspand
smcs.rspin your
Assetsfolder with each file containing the single line
-unsafe(note the leading dash). This tells the compiler to allow
unsafeblocks 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.