WARNING: As of Unity 2019.3, there is an official way to integrate Unity into an existing app, although it's not without its limitations. You should consider doing that intead of this procedure if possible.
-
Works as of January 2018 (Xcode 9, Unity 2017.0.2f3)
-
Note that we don't use the Unity-generated project at all here; instead, we add some of the Unity-generated files to our own Xcode project (either a native Xcode-generated project or the one generated by React-Native).
-
Also note that this is not a complete guide, however this contains the most hard-to-resolve issues that we encountered.
A combination of information found in those articles was used to perform our integration:
- https://the-nerd.be/2015/11/13/integrate-unity-5-in-a-native-ios-app-with-xcode-7/ (outdated but still a good overview)
- https://forum.unity.com/threads/unity-appcontroller-subclassing.191971/page-1
- http://www.makethegame.net/unity/add-unity3d-to-native-ios-app-with-unity-5-and-vuforia-4-x/
-
Roughly follow this guide: https://the-nerd.be/2015/11/13/integrate-unity-5-in-a-native-ios-app-with-xcode-7/
- Settings inside Unity itself are less important as they mostly affect the Unity-generated Xcode project, which we don't use
- Add frameworks as described (IMPORTANT!)
- Add groups and folder references as described (IMPORTANT!)
- But skip the build settings part; instead, transcribe all "Customized" build settings from the Unity-iPhone target in the Unity-generated Xcode project into the custom app (there is a "Customized" filter at the top of Xcode's build settings that makes customized settings easy to spot). This will ensure that the latest requirements of the Unity project are mirrored in our custom app.
- Set
Dead Code Stripping
to YES to avoid some more linker errors (https://forum.unity.com/threads/unity-arkit-plugin-faq.495191/)
-
Build the app for a real device (or Generic iOS Device); Simulator is not supported!
- Else some libraries will fail to link due to missing x86_64 architecture in the
.a
files - Specifically, this is an issue with
libil2cpp
(required for Unity) and Vuforia static libraries (if using Vuforia)
- Else some libraries will fail to link due to missing x86_64 architecture in the
-
Since ~ 2013, Unity unofficially supports taking control of the app delegate to simplify customizing the Unity-generated app.
- Use
IMPL_APP_CONTROLLER_SUBCLASS(AppDelegate)
to "subclass" the UnityAppController class. - Caution: Vuforia already uses this method to initialize its own stuff, so we must customize the Vuforia setup a bit in order
to be able to provide our own subclass. See
CustomVuforiaNativeRendererController.h/.mm
for details. - Don't forget to call superclass methods in the custom AppDelegate!
- The "officially" supported way to take ownership of the root app UI is to override -willStartWithViewController: in our custom AppDelegate
- Use
-
Unity MUST be initialized with the app (managed by its global
UnityAppController
) for it to work properly.- This implies that the Unity stuff is always loaded
- However, it can be paused and resumed at will using
UnityPause(1)
andUnityPause(0)
, preventing app slowness and battery drain.
-
When using new features in the Unity C# code, some files might be added in the "Native" directory of the Unity-built Xcode project. Make sure to update the "real" Xcode project to reference those files as needed!
How's the performance? Looking to use React Native for the UI layer, and dive into Unity for AR ...