How Unity Developers Can Reduce their Build Size with One Simple Step
Tags: tutorial, programming, unity3d, showdev
Published: 2021-03-25 21:23:11

**Calling all Unity game developers!** Looking for a way to dramatically reduce your overall app size when creating 3D apps with Unity? Try this simple step — **moving your 3D models to the cloud!**

Many players are hesitant to download large-sized apps & games. It takes more time, requires more bandwidth, and can really exhaust your phone’s data plan (or can even prevent your app from being downloaded when a player is interested but is not connected to Wifi). By moving 3D assets to the cloud, thereby, reducing the overall size of your app, you are addressing all of your players’ needs and more. Keeping your app size small and connecting it to the cloud means players will get the fastest download and freshest content.

**[echoAR](https://www.echoar.xyz/)**, one of the newest members of the Unity Verified Solutions Partners program, is a cloud platform for AR/VR/3D applications that provides tools and network infrastructure to help developers connect their Unity app to the cloud and quickly deploy 3D content in AR. echoAR offers a 3D-first content management system (CMS) and delivery network (CDN) and a scalable BaaS infrastructure that enables Unity developers to build an AR/VR app backend in minutes and easily manage and publish 3D content. **Here’s a step-by-step guide to how move your 3D models to the cloud and reduce your Unity build size dramatically:**


# 🔑 Get an API key

* Register for FREE at [echoAR](https://console.echoar.xyz/#/auth/register) and get your own API key (also check your inbox for an automatic email with your key).
* Upon registration you will be redirected to the console (you can also use the link in the registration email to get back to the console anytime.) Make sure your key is set in the header or type and load it yourself!

![2.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706085010/NSFrfK3iE.gif)

* **You did it!** 🎉

# 🔨 Install the Unity SDK

You can easily use echoAR as a backend for your [Unity](https://unity3d.com/) project by following these steps:

* **Download Unity SDK**: Click the “Downloads” button in the top header bar to directly download the echoAR SDK for Unity.

![3.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706135082/a6kT0qMVj.jpeg)

* **Open a Unity Project**: Create a new or open an existing project in Unity (make sure your Unity version is [up to date](https://docs.unity3d.com/Manual/index.html) and has the required modules to build an app on your platform of choice!)

![4.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706183504/_Vmh8QWAe.jpeg)

* **Integrate Unity SDK**: Double click on the *echoAR-Unity.unitypackage* file to import it into your Unity project. Alternativity, click *Assets > Import Package > Custom Package...* in the top menu bar and choose the *echoAR-Unity.unitypackage* file to import it into your Unity project.

![5.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706275477/UoBcDQzLM.gif)

* **That’s it!** 🎉

# 🧰 Using the SDK

* **Streaming 3D holograms into Unity**: Either open the sample scene under *Assets/echoAR/Examples/sample*

![6.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706300871/cVkS3otlz.gif)


![7.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706329788/u1ZQ2bKGm.gif)

* In the Inspector View for the echoAR game object or the empty game object that you created, update the *API Key* field with your API key.

![8.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706350512/W1-Ek2oX7.gif)

* [Add a 3D model](https://docs.echoar.xyz/quickstart/add-a-3d-model) through the [console](https://console.echoar.xyz/) ([here’s how](https://docs.echoar.xyz/quickstart/add-a-3d-model))

![9.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706393714/91uFKX3uW.gif)

* Go back to Unity and hit the **Play** button. The SDK will stream the 3D model into Unity.

* **Great work!** 🎉

# 📐 Transforming Content
* **Real-time updates and animations**: You can go back to the console to add more 3D models, delete 3D models, add metadata, or change existing metadata associated with your entry and instantly see the changes in Unity even **while the Unity project is running**.

* For example, you can [add metadata](https://docs.echoar.xyz/web-console/manage-pages/data-page/how-to-add-data#adding-metadata) with the key *direction* and the value *right*.

![10.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706480308/tzO6xBMZ4.jpeg)

* This will make the 3D model rotated to the right.

![11.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706498079/BLwJpYLQz.gif)

* **Build-in keywords**: Many metadata keys are already pre-defined and allow you to control real-time transformations (such as x, y, z, direction, scale, shader, etc.). See [here](https://docs.echoar.xyz/unity/transforming-content#build-in-keywords) for the full list (built-in keywords will also be suggested through a drop-down list in the console but you can add **any key** and **any value**).

# 👩‍💻 Edit code
* Now that you are able to successfully stream the 3D model into Unity, you can also make custom adjustments to it.

* Each hologram will be instantiated with a script named *CustomBehaviour.cs* attached.

* You can edit this script to create any behavior you would like while referencing additional data streamed from the cloud.

* Learn how to add code to your Unity project while getting data from the cloud [here](https://docs.echoar.xyz/unity/edit-code).

* **Great work!** 🎉

# 🤳 Adding AR capabilities

* Now that you are successfully able to stream 3D content into Unity and know how to make custom adjustments, its time to add AR capabilities to your cloud-connected Unity project.

* Unity provides a framework purpose-built for AR development called [AR Foundation](https://unity.com/unity/features/arfoundation). It allows you to build across multiple mobile and wearable AR devices, such as Android with ARCore and iOS with ARKit.

* Before using AR Foundation make sure that your iOS device is compatible with [ARKit](https://developer.apple.com/augmented-reality/arkit/) or that your Android device has [ARCore](https://developers.google.com/ar/discover/supported-devices) or [Google Play Services for AR](https://play.google.com/store/apps/details?id=com.google.ar.core&hl=en_US) installed.


**1. Installing AR Foundation**

* Clone the open-source [Unity + AR Foundation + echoAR](https://github.com/echoARxyz/Unity-ARFoundation-echoAR-example) example project on GitHub and open it in Unity.

**2. Setup a simple AR application**

* Open the AR Foundation sample scene located in: *Assets > AR Foundation > Scenes > SimpleAR > SimpleAR*

![12.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706670487/bA96zPrMm.jpeg)

* In the hierarchy click on the *AR Session Origin* game object.

![13.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706694707/DKnVO9tHB.jpeg)

* In the inspector view, look for the *Place on Plane* script and set the *Placed Prefab* to the echoAR prefab in the *Assets > echoAR* folder.

![14.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706721932/xRMinMFgH.jpeg)

**3. Set you API key**

* Edit the echoAR prefab and set your API key through in the Inspector view.

![15.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706748670/cRsftpCQF.jpeg)

* **Want to test the app in Unity before building?** You can test the connection to echoAR by pressing *Play* to start the app on Unity.

* Note that the *Game* view will show a black screen - that is expected as the *Game* view tries to access the mobile AR camera which doesn't exists when running on a desktop machine.

* Switch to the *Scene* view and drag the echoAR prefab from *Assets > echoAR* into the hierarchy.

* If the API key was set correctly you should be able to see 3D assets from the echoAR console stream into Unity.

* Stopping Unity from playing should reset everything.

* You are now ready to build the AR app on a mobile device.

**4. Build and run the AR application**

* Connect your [ARKit](https://developer.apple.com/augmented-reality/arkit/)/[ARCore](https://developers.google.com/ar/discover/supported-devices)-compatible mobile device or AR/VR headset to your desktop machine using a USB cable.

* Go to *File > Build Settings...* or press *Ctrl+Shift+B*.

![16.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706853183/zLCHfvPLm.jpeg)

* Make sure to set your platform to (either Android, iOS, or Universal Windows Platform (UWP), etc.) by choosing the target platform and press the *Switch Platform* button on the bottom right corner.

![17.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706872961/UuqBQZ5ym.jpeg)

* Verify that the *SimpleAR* scene is ticked in the *Scenes in Build* list and click *Build And Run*.

![18.jfif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706902503/6x_vkmuge.jpeg)

**5. Use your AR application**

* First, [add a 3D model](https://docs.echoar.xyz/quickstart/add-a-3d-model) to the console.

* When the application is loaded on your mobile device you might be asked to approve camera access permission.

* Move the phone around until a surface is detected.

* Tap the screen to place the model on the surface.

* The model will steam and render in front of you.

![19.gif](https://cdn.hashnode.com/res/hashnode/image/upload/v1616706950332/Zs4xD8fy9.gif)

* If the model is too big or too small, go back to the console and [add metadata](https://docs.echoar.xyz/web-console/manage-pages/data-page/how-to-add-data#adding-metadata) to affect its scale. After adding metadata the model should change automatically.

* **You did it!** 🎉

# ❔ Troubleshooting

Troubleshoot issues [here](https://docs.echoar.xyz/unity/troubleshooting). You can check out our full documentation for other useful tutorials [here](https://docs.echoar.xyz/) and also reach out to our support team [here](http://go.echoar.xyz/join).

***

> echoAR (http://www.echoAR.xyz; Techstars ’19) is a cloud platform for augmented reality (AR) and virtual reality (VR) that provides tools and server-side infrastructure to help developers & companies quickly build and deploy AR/VR apps and experiences.


![20.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1616707037416/rrBjKQjMs.png)