Search Unity

Unity 2019.3 will add support for using Unity as a library controlled by native Android/Java and iOS/Objective C apps so you can easily insert AR and other Unity features.

We know there are times when developers using native platform technologies (like Android/Java and iOS/Objective C) want to include features powered by Unity in their apps and games. Starting with Unity 2019.3.a2, you can integrate the Unity runtime components and your content into a native platform project so you can use Unity as a library.

This means that you can now insert features powered by Unity, such as augmented reality (AR), 3D/2D real-time rendering, 2D mini-games, and more, directly into your native mobile apps.

How it works: Changes to project structure

The Unity runtime library exposes controls to manage when and how to load/activate/unload within the native application.

The mobile app build process overall is still the same. Unity creates the iOS Xcode and Android Gradle projects.

However, to enable this feature, we changed the structure of the generated iOS Xcode and Android Gradle projects as follows:

  • A library part – iOS framework and Android Archive (AAR) file – that includes all source files and plugins
  • A thin launcher part that includes app representation data and runs the library part

You can find out more details about the changes to the Xcode/Android Gradle projects in this forum post.

We also have step-by-step instructions on how to integrate Unity as a library on iOS and Android, including basic sample projects.

Please note that using Unity as a library requires that you deeply understand the architecture of Android/Java and iOS/Objective C applications.

Some limitations

We tested many scenarios for Unity as a library hosted by a native app. But since Unity no longer controls the lifecycle of the runtime, we cannot guarantee it will work in all possible use cases. For example:

  • Unity as a Library supports full-screen rendering only; rendering on only a part of the screen is not supported.
  • Loading more than one instance of the Unity runtime is not supported.
  • You may need to adapt third-party plugins (native or managed) for them to work properly.  

Powering the technology that is revolutionizing marketing campaigns

Unity as a library is a tremendous advantage for various use cases across industries. In particular,  brands and creative agencies can now easily insert AR directly into their native mobile apps.

Cutting-edge brands see the value in adding AR to their traditional marketing campaigns. With Unity support for Unity as a library, the process is streamlined. Brands and creative agencies no longer have to rebuild their app to insert AR or hack together a solution to use Unity as a library.

Consumers are ready for AR marketing. AR lets brands foster a personal relationship with consumers, and we’re excited to offer a solution that powers the evolution of marketing.

To learn more about how brands and creative agencies are using Unity, check out our solutions page.

30 评论

订阅评论

留下评论

您可以使用这些HTML标签和属性: <a href=""> <b> <code> <pre>

  1. > Unity as a Library supports full-screen rendering only; rendering on only a part of the screen is not supported.

    Not supported as in “and will never be” or as in “but will be in the future”? :D

    1. Hi David,
      Not supported for now.
      We are considering it but it’s a tricky scenario where Unity needs to share resources with the native app. We don’t have a timeline yet, and are looking for feedback on what scenario make sense for you.
      Please jump on the forum post to share ideas.
      JC

  2. It would interesting to have it running under a Cordova hibrid App

  3. I can use this for AR in a lot of my applications so I’m excited! My only request is please release a tutorial or youtube video on an example of how to put this together as it might be a bit confusing doing guesswork once it releases.

    1. we are making more samples but the one shared on the forum linked in this blog post should give you all the building block you need.
      don’t forget, as I wrote:
      “Please note that using Unity as a library requires that you deeply understand the architecture of Android/Java and iOS/Objective C applications.”

  4. Honestly, this was a lot more impressive until I saw “supports full-screen rendering only.” Really, every potential idea I had up until that point was cast aside.

    1. Hi Liz,
      Please share your ideas on the forum. we are listening ;-)
      As responded on another similar question:
      We are considering it but it’s a tricky scenario where Unity needs to share resources with the native app. We don’t have a timeline yet, and are looking for feedback on what scenario make sense for you.

  5. Could I write a Apple Watch app with Unity with this change?

    Like running the engine on the watch itself without a phone companion. Ideally I’d like my game to run both the watch and my phone so I can have a shared codebase.

    1. Hi,
      No, Unity does not support Watch OS, and no plan for now.

  6. Thank you for sharing this good information. Mobile Application Development is an interesting field. Our website have many packages about App Development. You can visit:
    App Development Packages

  7. Is it planed to be just for mobile?
    It could be amazing to use Unity rendering capabilities as a runtime for native desktop apps.
    I’m thinking in the direction of embedding Unity as a set of nodes for TouchDesigner for example.

  8. Unity, just go ahead and build us something for Python. The ML interface is Python, the new UI scripting stuff supports python – just go ahead and give us python support @ the engine and be done with it :)

    1. Using Python would violate the Performance by Default goal.

    2. Aside from the terrible performance implications, why would you actually need this? C# really is not that hard to learn and write. You use the right tools for the right job. Python is used for machine learning because its an industry standard and performs well for AI. The same cant be said about python and the rest of use cases, so really putting it for the rest of the engine just takes us back to the point we were with javascript.

      If you to write in python, why not just move to an actual python based graphics engine?

      1. Because Unity has made a mission of making Unity a platform for more than just games. So while it is true that for regular games it would be a problematic issue – for other use cases (including as a teaching environment), Python would be excellent.

        1. They used to have Boo script, ie it was “python” the same way that unityscript was “javascript”

    3. Hi Gregory,
      if you care about Python for ML scenarios, please check “Unity ML Agents”:
      https://unity3d.com/machine-learning
      Unity Machine Learning Agents, the first of Unity’s machine learning product offerings, trains intelligent agents with reinforcement learning and evolutionary methods via a simple Python API.
      We don’t plan to add any new language to Unity for now. C# it is.

      1. Certainly JC, that’s where I currently interface with Unity for a number of RL things. Even tried to build something with IronPython a while back because Python is a good teaching/learning language. But I know you guys are busy rebuilding pretty much all of the Unity that I used to know (and that’s a good thing), so maybe when you’re done with that ;)

  9. Can’t wait for a python interface! it would be great for machine learning research projects!

    1. look at “Unity ML Agents”:
      https://unity3d.com/machine-learning
      Unity Machine Learning Agents, the first of Unity’s machine learning product offerings, trains intelligent agents with reinforcement learning and evolutionary methods via a simple Python API.

  10. this one is cool i really love these updates by Unity, i have a past of game development but now i am an full time app developer at https://appdevelopmentagency.com.au/. working in a professional environment boosts my creativity i am a fan of Unity.

  11. Any word on how big the framework and aar will be for an empty project?

    1. You can consider that the size of the final binary is the same than a normal Unity project.

  12. Now, this would also be great on PC. We currently prototype the integration of Unity in a WPF application and had to setup a client/server structure to handle communication between the app and Unity…

    1. @Stefan Maton @Unity

      For some of our projects, we have implemented the same type of TCP communication protocol between a Unity application and a WPF / WinForm application. With the addition of the management of the inclusion of a Unity window in a WPF / WinForm Panel (SetParent, …). This works well but it would be comfortable to have native support for this type of integration.

      1. It would certainly be great to have an easier integration of Unity into desktop apps too, e.g. Qt programs. Currently, we have a setup that uses some shared memory and communicates over a lot of callbacks. But this is super cumbersome.

    2. This is in fact already possible for PC, and has been for some time now, though admittedly it isn’t well documented. We are planning to include documentation for how to embed Unity as a library for desktop platforms soon. Stay tuned.