Integrate Unity 5 in a native iOS app
A few months back I published a blog post about how to integrate Unity3D within a native iOS application. This tutorial was written for Xcode 6 & Unity 4 and in the comments there were a lot of requests for a new tutorial.
Tonight I found the time to make the video tutorial on how to integrate Unity 5 in a native iOS app with Xcode 7, so I hope you enjoy it!
I hope this can help some of you guys out, because integrating Unity3D within a native iOS app isn’t that easy, but I’m really happy with the setup that I have right now.
Prerequisites
The version of Unity that I use is 5.2.2f1 and Xcode 7.1.
Video tutorial: integrate Unity3D within a native iOS app
You can check out the video on Vimeo – Add Unity3D in native iOS application. If you have any questions, just put them in the comments, or contact me via Twitter. I hope you know understand how to integrate Unity3D within a native iOS app.
134 Responses
Thank you very much for the tutorial!
This tutorial is amazing! We have tried it, integrating is success, but when we are a Vofuria Project, when we start the Unity, we just can see black screen, and we can’t find out the problem.Can u help?
we r using Xcode7 and unity5.2
Hi, I faced your same problem. My problem was because when vuforia unity works before native integration, the “AppControllerClassName” is not “UnityAppController” but “VuforiaNativeRendererController”. So if we change “AppControllerClassName” to AppDelegate ,
“-(void)shouldAttachRenderDelegate” in VuforiaNativeRendererController will not be called. Thats why my screen showed black. Check your Libraries>Plugins>ios. There is a file “VuforiaNativeRendererController.mm”. Comment “IMPL_APP_CONTROLLER_SUBCLASS(VuforiaNativeRendererController)”. Copy paste the “- (void)shouldAttachRenderDelegate” method to UnityAppController.mm. See whether it works.
I’ve added another solution in the comment above, in your version you will have to re-add the `shouldAttachRenderDelegate` every time you rebuild from Unity which can be a pain in the ass 🙂
Hi Frederik! your tutorial are awesome .Could you do some extra tutorial after this about how implement vuforia? So many people want to do this. Will be very useful. Thank you!!!
I’ll see what I can do. At the moment I have a lot of other work which has priority right now.
Maybe in the upcoming weeks I’ll try to make a Vuforia tutorial.
Kind regards,
Frederik
Hi, Frederik!!
Thanks, this was very helpfull for me and my teammates for an important project using Unity, Vuforia, Objective C and Swift.
As you said it will be great to have an complete tutorial of that, but I have a crazy idea, we create a project demo using your tutorial and maybe we can help you sending a video with final little steps for connecting with Vuforia and Unity. This can help you (time trouble for making it) and help other people that have the same problem as we have it.
hi Frederik any Vuforia tutorial for us?please …..
Please I try to implement Vuforia, i have follow all steps of this video but i don´t know the steps to follow after this to makes vuforia works. Thank you babybet
Yeah with vuforia you have to remove the following line of code in the file
`Libraries/Plugins/iOS/VuforiaNativeRendererController.mm
Then you have to add de `renderDelegate` in your AppDelegate file.
At the top of AppDelegate, you have to add the following line of code, right before the @implementation AppDelegate
Kind regards,
Frederik
Dear Frederik,
Using your and Babybet’s suggestions I’ve managed to get my camera working. Unfortunately, nothing happens when I point it at the marker. Perhaps I implemented the Event part wrong?
I’ve tried both the way you described as well as a equivalent for Swift (my project is in Swift), neither seem to work.
Any ideas? Thanks again for your time!
I’ve implemented Vuforia and it detects the marker but the screen is black, i’ve also implemented shouldAttachRenderDelegate but it’s never called
Ok i fixed it, you should call shouldAttachRenderDelegate from “UnityAppController+Rendering.mm” in callbackGfxInited
In Classes > UnityAppController+Rendering.mm > line 72 callBackGfxInited
replace the method callbackGfxInited by this:
Thank You!, i get this
Thank you Fábio to your answers! But i have a problem with this line , could you know why happens this?
Then You have to change something in AppDelegate.h and AppDelegate.mm? Your previous post with AppDelegate.h is correct?
i Copy all like your code but i get this error in UnityAppController.mm
Add you added the “shouldAttachVuforiaRenderDelegate” to your AppDelegate.h?
This is my AppDelegate.h:
#import
#import “ViewController.h”
@interface AppDelegate : UIResponder
@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UIWindow *unityWindow;
@property (strong, nonatomic) UnityAppController *unityController;
– (void)showUnityWindow;
– (void)hideUnityWindow;
– (void)shouldAttachVuforiaRenderDelegate;
@end
This is AppDelegate.mm:
– (void)shouldAttachVuforiaRenderDelegate {
self.unityController = [[UnityAppController alloc] init];
self.unityController.renderDelegate = [[VuforiaRenderDelegate alloc] init];
UnityRegisterRenderingPlugin(NULL, &VuforiaRenderEvent);
//Unity native rendering callback plugin mechanism is only supported
// from version 4.5 onwards
#if UNITY_VERSION>434
UnityRegisterRenderingPlugin(NULL, &VuforiaRenderEvent);
#endif
}
And the UnitAppController.mm:
#import “AppDelegate.h”
– (void)shouldAttachRenderDelegate {
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[delegate shouldAttachVuforiaRenderDelegate];
}
When te app runs and i touch “Show unity” log says:
2015-11-20 14:59:55.999 Unity5Native[8398:3795519] [ViewController] Show unity button touched
2015-11-20 15:00:02.639 Unity5Native[8398:3795519] [ViewController] Show unity button touched
2015-11-20 15:00:03.269 Unity5Native[8398:3795519] [ViewController] Show unity button touched
2015-11-20 15:00:03.771 Unity5Native[8398:3795519] [ViewController] Show unity button touched
Thank you Fábio for your time!
Iam not an objective c genius this is my first time Codding in ios but your first import it’s not with an error?
Only first time that i have running the app it changed to UnityWindow. But only see black background
Hi Kevin could you paste the code add to AppDelegate.h and mm? Thank you!
Hi Frederik,
thanks for this awesome tutorial. Helped me alot.
I am now facing problems with integrating Vuforia, too.
I did what you wrote here (you also have to rename the AppDelegate to .mm) and now I can perfectly see my camera image but tracking doesn’t work. nothing happens. no console log, nothing. do you have any idea?
in my unity project my target is setup inside the imageTarget and the target is activated in my ARCamera as well.
I’d love to see a Vuforia tutorial, too 🙂
I got it to work now 🙂
Just had to add the /Data/Raw/QCAR folder in Build Phases -> Copy Bundle Resources although I had it already in my Vendor/Unity/Data folder reference. So now I have my .dat and .xml of the image target twice, but hey it works
Is there a way to fix the black screen issue without having to change the AppDelegate to .mm ? When i do that, the CGLConfiguration from my GoogleMaps pod says ‘Use of @import’ when modules are disabled but Enable Modules is set on YES. Im feeling stuck between a rock and a hard place.
everything goes well but in the end i had this issue, can u help me ?
Woot! Thanks Frederik. It worked! This is a great starting point for people trying to launch their Unity games from native apps.
Thanks, glad you liked it!
Great tutorial, thanks.
I see in the video that you hide the unity window with “[self.window makeKeyAndVisible]”. How can I call this method from Unity? Or is there another way to cancel the Unity scene and go back to the native screen?
Thank you!
There is a possibility to communicate from Unity to Objc by using a bridge.
You should check out http://docs.unity3d.com/Manual/PluginsForIOS.html
i all ready have the existing code with storyboard. i like to add the button i home page which it will redirect me to unity game. how can i achieve this?. thanks in advance
This video tutorial will work with unity and vuforia project?
Thank you!
Hi people! I have follow all steps. I want to use Vuforia but when i compile get image error.
Also i have commented line:
Hi team. I have unity+vuforia same versions of this Tutorial. When i finish this tutorial i go to Library Search Paths (build settings tag) and i add folder where is libVuforia.a.
Next step: I go to VuforiaNativeRendererController.mm and comment the line //IMPL_APP_CONTROLLER_SUBCLASS(VuforiaNativeRendererController)
I don´t know what´s next step. I get allow permissions to Camera and when i tap to “ShowUnity Button” i get blackscreen.
All help is welcome 🙂 Thank YOU!
Hi people! I have an important project and i have so many problems to implement vuforia with this tutorial. Anyone get this? Could share the project will be very useful. Thank you!!
Thanks a lot, super helpful tutorial!
Hrmm, I can’t get a build to run.. its always missing a header, every time i get “il2cpp-config.h” file not found
Lot of run time errors followed this tutorial step by step. Using it in xcode 7.2 and unity 5.3.0f4 . Also Can we have this video in youtube? 🙂
Lot of run time errors followed this tutorial step by step. Using it in xcode 7.2 and unity 5.3.0f4 . Also Can we have this video in youtube? :)1
1. Lot of run time errors followed this tutorial step by step. Using it in xcode 7.2 and unity 5.3.0f4 . Also Can we have this video in youtube? 🙂
Hi Prajeet,
I’m uploading the video to Youtube as we speak (https://youtu.be/RUmrRHeS7BU). I can’t help you any further with your errors, as it is probably a build setting or so that is not correct.
Thank you so much for this tutorial Frederik! I am having an issue trying to complete this tutorial with a Unity Project that’s using the Google Cardboard SDK. Specifically, I am getting Uncaught exception: NSInvalidArgumentException: -[CardboardAppController unityController]: unrecognized selector sent to instance 0x15f6c33b0.
Xcode sees two AppControllers, the “CardboardAppController.mm” in the iOS/Plugins/ folder, and the “UnityAppController.mm” in the imported “Classes” folder… Any advice on how to merge or bridge the two?
Hi Andrew, Did you find a solution to overcome this issue?
Hi Frederik !
Great job, but do you managed to display Unity in a subview of the native window of an existing project ?
For me, it works in a new “Hello World” project, but not in my real project, in this case the app crashes with EXC_BAD_ACCESS in UnityPreload 🙁
Hi Sébastien,
Yeah I’ve used this technique in 3 live apps without any problem.
I am having this exact same issue. It fails inside UnityAppController::UnityInitApplicationNoGraphics, something wrong with the MountHandler/FileSystem?
Hi Andy, were you able to find the cause for crash? I am facing the same problem right now. Thanks in advance!
Same problem here, any luck with this?
Hi Sébastien, were you able to find the cause for crash? I am facing the same problem right now. Thanks in advance!
Hi Jayesh,
Unfortunately not, and as it was a POC we decided to drop this integration 🙁
Hi Frederik, thank you for this great tutorial!
All works well. I would to know how can I call my CSHARP class and relative methods or simply the “default” animations of the asset?
My current error is:
“Undefined symbols for architecture arm64:
“_SpiderController__ctor_m6_0″, referenced from:”
I’ve found this
http://www.markuszancolo.at/2015/04/unity-5-with-il2cpp-into-ios/
but I’m not able to integrate with your tutorial.
Thanks!
same issue while trying to add c sharp scripts to the unity code base and trying to build the xcode project. Could you please let me know incase if you find any solution for this.I am really facing a tough time to resolve this. Tried by chaning the scripting backend from il2cpp to mono2x and all other combinations in player settings. But none of them worked fine 🙁
Hey Alessio. I fixed these issues in my project.The issue was not with the unity,We have to re import the native class cpp files from the unity generated xcode project to our project and it would have been created those files for you.
Thank you ravoori for suggestions, actually I’m not working on the project of two month ago, but I remember I had fixed developing in mono2x
Hi, Frederik. Great tutorial. You helped us a lot, really appreciate it.
We could create a unityview window using unitygetmainwindow, and it worked fine.
But unfortunately we failed to resize it or create a subview. We think we should use either UnityGetGLViewController or UnityGetGLView, however they never worked for us. We are Unity3d programmers, and quite new with IOS. Could you give us a hint?
Thanks
Hello Frederik! First, i’m amazed that people do all this work and then care to share it. Hope i can do the same some day!
This said, i am having the same problem that prajeetshrestha submitted about 20 days ago. The errors he show (and that i show too) seem to be pointing all to the foundation framework. I work also with 7.2 and the latest ios9.
Can you tell us something about it? Some clue, as to where to point, not only “some build setting”, because theres a lot of build settings you made us change 😀
Thank you very much again!
Hi! I’ve been following the tutorial but I’m having some issues when it comes to compile and show the blue view. The error I’m facing is the following: ‘Unknown type name ‘UnityViewControllerBase” on UnityAppController.h on line 24. I workarounded this by commenting the import of UnityAppController.h in prefixHeader.h and doing it on AppDelegate.h, but, when I try to create the AppDelegate in UnityAppController.h the build fails with the following error: Use of undeclared identifier ‘AppDelegate’. What can I do?
Same problem here. I tried to move the #import into individual files but then I hit a problem when modifying the UnityAppController file to refer to my AppDelegate.h. I’ve triple-checked build settings and can’t figure out what’s different from the example. ARG!!
Big thanks for the tutorial though, I’m so close!
Hi, i managed to get it works.
So, after i comment the #import “UnityAppController.h” line in PrefixHeader.pch and put the line #import “UnityAppController.h” in AppDelegate.h, I encounter the same problem (as stated above). I manage to solve it by using the method used in https://github.com/blitzagency/ios-unity5#adjust-the-getappcontroller-function-in-unityappcontrollerh. In summary (credit to blitzagency from the above url), I change the
inline UnityAppController*GetAppController()
{
return (UnityAppController*)[UIApplication sharedApplication].delegate;
}
to
NS_INLINE UnityAppController* GetAppController()
{
NSObject* delegate = [UIApplication sharedApplication].delegate;
UnityAppController* currentUnityController = (UnityAppController *)[delegate valueForKey:@”unityController”];
return currentUnityController;
}
That way, it will point to the correct unityController without triggering the “Use of undeclared identifier ‘AppDelegate'”.
I hope it helps and thank you very much for the tutorial!
Xcode Version: 7.3
Unity runtime version:5.3.5f1
—————
I meet the same problem : “Unknown type name ‘UnityViewControllerBase’ blablabla…” too. And I follow your solution, it works, but we just need to do part of it.
”
Step 1: Comment the #import “UnityAppController.h” line in PrefixHeader.pch
Step 2: Put the line #import “UnityAppController.h” in AppDelegate.h
”
then, I run the app, it works.
I have the same problem: ‘Unknown type name ‘UnityViewControllerBase” on UnityAppController.h on line 24. So I also ave errors in UnityViewControllerBaseiOS.mm
Cleaning project the errors in UnityViewControllerBaseiOS.mm disappeared. Still ‘Unknown type name ‘UnityViewControllerBase”. I tried William’s solution but it doesn’t work for me.
Replace UnityViewControllerBase with UIViewController, it’ll work now
have you solve this issue?
Hi bro! Thank u so much for this tutorial and i learnt a lot by this tutorial. But i have another problem and here it is. I used vuforia for my unity app. when i run the app it gets the following erro “library not found for -lVuforia” can u please help me. I want to integrate ar to an existing iOS app
Hi Frederik!
Thanks a lot for this wonderful tutorial. But i’m having an issue to integrate a project which is using Vuforia for AR. So can u please add a new tutorial for Vuforia example.
Hey, Where you able to resolve vuforia problem?
Hi! Thanks for the tutorial, it is really good and useful, however I am getting a problem at some point. After modifying appDelegate and trying to running first time I got an error link and I cant figure out how to fix it… error is the following:
Undefined symbols for architecture arm64:
“RegisterStaticallyLinkedModulesGranular()”, referenced from:
RegisterStaticallyLinkedModules() in libiPhone-lib.a(RegisterStaticallyLinkedModules.o)
“RegisterAllClasses()”, referenced from:
InitializeEngineNoGraphics() in libiPhone-lib.a(SaveAndLoadHelper.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any idea?? I have already checked when I export in Unity to set architecture: Universal and scriptingBackend to il2cpp
Thanks a million in advance! 🙂
Hi Juan,
i have similar error as yours. You can try the following solution, re-add/add these framework in your project build phrases (link Binary with Libraries) Security, System Configuration or the libiPhone Lib.a in your libraries folder. I did this to solve the following error:
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(source from: http://answers.unity3d.com/questions/1110053/anyone-else-having-issues-with-53-and-xcode-72.html)
i have the same issue. did you solve it?
can u provide sample project pls
everything works perfect !!! thank you soooo much
Hi! Can you share xcode project code?
I followed all of the steps and it works well. But my iPhone camera does not close while the app is running, and my phone is heating up because of camera. I don’t know how to stop or close the camera.
CameraCapture.mm inside the Unity classes contains the following, but I have no idea how to call this method from my native ViewController:
extern “C” void UnityPauseCameraCapture(void* capture) {
[(__bridge CameraCaptureController*)capture pause];
}
Hi Frederik,
Fantastic tut. And also thanks to all pre-posts.
Now I can call Unity Vuforia Camera in native IOS but I have some issues to be fixed:
1. When I launch iOS App, I found UnityWindow is shown in portrait by default without calling showUnityWindow() and native iOS window is shown in landscape (which should be portrait. Then I press the button to call showUnityWindow(), the natvie IOS window is gone.
2. I integrate AR Vuforia as well, press button Camera view is ok but cannot track image target. I also tried /Data/Raw/QCAR folder in Build Phases -> Copy Bundle Resources. Also I am confused whether I need run script in latest version or not? Seems we directly copy Data to project so do not need it any more?
3. Finnally when I test on my iphone via xcode, it always crashes at the beginning at point of extern “C” bool AllocateRenderBufferStorageFromEAGLLayer(void* eaglContext, void* eaglLayer)
{
return [(__bridge EAGLContext*)eaglContext renderbufferStorage:GL_RENDERBUFFER fromDrawable:(__bridge CAEAGLLayer*)eaglLayer];
}
The reason is showing as EXC_BAD_ACCESS, any idea?
BR
Caesar
i have the same problem?have you solve it?
Hi Thanks for the tutorial. This is very much helpful to everyone like me, who is new to Unity.My only question is i already have an iOS app which has 10-11 views. And i want to present this unity view some where in the middle of the application for example in 5th screen. For instance user will be logging in and in the home screen i want to show a unity object in some part of it. please let me know how can i acheive this.
Also could someone let me know, how should i communicate with the Unity Player, for example if i want to execute some unity scripts on unity player,how can i achieve this from my iOS app.
Hi, thankyou for the useful guide but when I build the project Unity5Native, xcode shows me the error:
Undefined symbols for architecture arm64:
“RegisterStaticallyLinkedModulesGranular()”, referenced from:
RegisterStaticallyLinkedModules() in libiPhone-lib.a(RegisterStaticallyLinkedModules.o)
“RegisterAllStrippedInternalCalls()”, referenced from:
RegisterAllInternalCalls() in libiPhone-lib.a(MonoICallRegistration.o)
“RegisterAllClasses()”, referenced from:
InitializeEngineNoGraphics() in libiPhone-lib.a(SaveAndLoadHelper.o)
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I use Xcode 7.2.1 unity 5.3.2f1
Can you help me to resolve it? thanks!
Man, i have the same issue. Than i change my Machine. And this error was solved. I don’t know what is this.
Probably this thing was related to my version of OS. Because my old machine have Yosemite e my new is the Captain.
https://www.dropbox.com/s/ywxvs4h9kp1qyxk/%E8%9E%A2%E5%B9%95%E6%88%AA%E5%9C%96%202016-04-06%2023.27.55.png?dl=0
I’ve been following the tutorial but I’m having some issues.
how to fix it ?? Thanks
I have Same Issue… is there anyone fix it?
In the project Build Settings > Apple LLVM 7.1 – Warnings – All languages, change “Mismatched return type” option from Yes to just Yes
I’ve made tutorial for Unity + Vuforia based on your videos and bunch of other sources,
maybe it will be useful for someone
https://github.com/keyv/iOSUnityVuforiaGuide
So, so many thanks!! you saved my day a lot!!
thanks for your tutorial, i am using unity 5.3.4 and vuforia 5.5.9 (for sample i am using vuforia best practices, Books) but when i integrating it, success, but the camera is blank, there is this message ini log:
Could not find a UIView with CAEAGLLayer or CAMetalLayer layer class that responds to selector renderFrameVuforia
well, I have the same unity and vuforia versions and used my tutorial a lot and everything works. Have you disabled Metal in unity project?
I have the same issue that Sayyid Ahmad has, but my camera open but the target cant be read… is there some config with vuforia on XCode to make it work properly ?
Thank you so much to the original author, and to keyv for simplifying the process with a step by step guide. keyv, your guide worked great for me! Since you did so well on this, I’m wondering if you have a similar guide for Android + Unity + Vuforia?
Hello, i follow the tutorial but i have this issues , Any idea?https://uploads.disquscdn.com/images/92cae74f50a8680cadc66fa2037b3e0f5ceb0e44d65e5c482aa92dcbf013ceac.png
i have an issue in camera capture.mm file. the issue is ” Use of undeclared identifier ‘static_assert’; did you mean ‘static_cast’?”
in the line
static_assert(countof(presetW) == countof(preset), “preset and preset width arrrays have different elem count”);
i made the tutorial many times.
Hello keyv , i follow your tutorial and all works fine!!!! thanks a lot!!! you are my hero!!!! lol , but i have a little problem, every time i show the unity window, the memory of the app rise in 10mb !!!!!! , any idea whats happenning?
hi Frederik
this is an awesome tutorial.
I am trying to build a framework for my app so that other developers can integrate my unity project in their native project.
Can you help me in figuring out how to make that process easier for them and the best way to build the framework in this manner.
Thanks and all the help is appreciated
This article is awesome ,but there are some errors in unity 5.3.5f1 with xcode 7.3.1. But it is easy to fix.Thx nerd give us such amazing and useful article.
hello I have this issue. All appear in the same line.
have you tried to add #import “AppDelegate.h” in the beginning of the file?
Yes, i Try https://uploads.disquscdn.com/images/e27a9c08347800df8fbb6f6790deb1b4e5e16c6e9310ad069bf7937371691097.png
check if you have it in AppDelegate.h
and try to write in 2 lines:
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[delegate showUnityWindow];
the same issue https://uploads.disquscdn.com/images/d59d64183db3ffc1e3195afe77c7c25ad5c7c1f25d2b634fd4447196a7c50302.png
The isuue is in the line “[delegate showUnityWindow]; ” and i add “#import “AppDelegate.h” “
maybe there is something wrong in the bridge https://uploads.disquscdn.com/images/4c78cd943d33830114b7698092d1cca40eafd378cc329681e71b35fe22851070.png
Hi! I’ve been following the tutorial but I’m having some issue when it comes to compile.
The error I am facing is the following: “clang: error: unknow argument: ‘weak-ISystem’.
What can I do? Please help me resolve this issue. Thanks!
i have the this issue and i re add all the frameworks, clean the projects . any other idea ?
Works good on Unity 5.4.0f3 and Xcode 7.3.1. How to launch it on a subview without being full screen? Very good tutorial :). Tanks in advance for the help.
I’ve followed this guide on point, 2 times in a row and I get the exact same linker issues.
Were you able to fix this? I am having the same issues only when I try to generate the project using simulator as the target SDK. If I generate the project for a Device everything works well.
We gave up on this approach and are now coding in Unity for the most part with the occasional iOS plugin, then we build for Xcode and test.
Just curious, were you generating the Unity project for the simulator target and building your xcode project against the simulator? Because that is how I am getting that error. If I set the player setting target SDK to device in Unity and then build the Xcode project using a device as target everything works.
Hi,
I had this exact same issue.
The solution is in the Build Settings in other linker flags (OTHER_LDFLAGS) add: -Wl,-undefined,dynamic_lookup
Hi
This tutorial clear many things. Thanks for this amazing demo.
After following all things. I’m getting following errors regarding “libiPhone-lib.a” framework.
ld: library not found for -liPhone-lib
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Can you please help me to get rid on this?
This is incredibly helpful.
One question I’m sure a lot of people have (and that took me a couple of hours to figure out) is – how does one get back to the native view from inside of Unity?
I’m sure you could figure this out in thirty seconds, but for the Obj C noobs who came looking for an easy integration–
Create a .mm file and put it in Unity Project > Assets > Plugins > iOS
Paste all this stuff
#import
#import “AppDelegate.h”
@interface MyUnityPlugin:NSObject
+ (BOOL)hideUnityWindow;
@end
@implementation MyUnityPlugin
+ (BOOL)hideUnityWindow {
AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[appDel hideUnityWindow];
return true;
}
@end
//C-wrapper that Unity communicates with
extern “C”
{
bool uHideUnity(){
return [MyUnityPlugin hideUnityWindow];
}
}
___________
Then make a C Sharp script called HideUnity, paste this code in and hook the hide function up to a button in UI 🙂
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class HideUnity : MonoBehaviour {
[DllImport (“__Internal”)]
private static extern bool uHideUnity ();
public void hide(){
Debug.Log (“Trying plugin…”);
if (uHideUnity () == true) {
Debug.Log (“Successfully returned data from external plugin”);
}
}
}
Hello, i do exactly same what is in the video. But i get error in files where include path is defined, it gives error if path is defined with folder name . and when i remove folder name it solved error . Does it have any setting to include files with folder name ? Because if i have to do changes in so many files 🙁
Hi, Thank you so much for this awesome tutorial. But I encountered a problem with orientation. My Unity project supports only landscape left and my native iOS app supports only portrait. But in my native project I’ve set the settings to support all 4 orientations and locked some of my views to only support portrait. But when I try to show the Unity window, it also opens in Portrait mode. Does anyone has a solution to this issue?
Hello!!!!
I followed the tutorial and all works fine!!!! thanks a lot!!!
But i have a little problem, when i show the unity window and then hide it, i have a memory leak of 10mb!!! so when i present the unity window like ten times , the app crash!!
Hi Eduardo, did you figure out the fix for this crash? I am having the same problem right now. thanks in advance!
Hi Jayesh!!!! , no!!! the issue continues! :(, fortunately the app doesn’t reach production environment yet…. lol
If i find something, i will post it here!!!
Fantastic ! exactly What i Was trying to Achieve !
Just one question,
What about it I want the Unity Scene to start only when display the unityWindow ?
IS there anyway to achieve this ? I dont know much about Objective C unfortunately !
Aswel, once the Unity Scene start, how to create a button to go back to the original window ?
Thanks a lot for your time 🙂
Hi,
@The-nerd
I exporting Unity app into framework, but It crashes at the following line,How can I solve this problem? https://uploads.disquscdn.com/images/850f9ea028e56562554a08ea38122413f678b6e98ac5abc81b4181f6e2e80e1e.png
Hi chengjun,
did you find the solution for the above problem ?
Hi there, i have a repository on Bitbucket with another way to integrate and the final project to download.
https://bitbucket.org/jack_loverde/unity-5-vuforia-6-and-ios-native-integration
I made for my project and distribute e example project with tutorial.
Glad if it help someone.
Thanks
Hi i am getting use of undeclared identifier AppDelegate.h in UnityAppController file http://www.screencast.com/t/uJSkiny8tZ
You rock man… Unity 5.4.3f and Xcode 8.1 and works
hi, i know it’s a bit old but i wonder if there are any swift (3?) version of this tutorial ?
i’m currently facing the use of swift 3 library through Unity 5.5 and i’m completly lost
=)
Would this work with Swift 3? The only issue I can see if the C++ integration.
Hello, whether the Unity of the project package into a framework of the form, integrated into the existing project
Amazing guide, I do everything and remove all linker error. But now when I start Unity on my App, I get black blank screen and nothing more. Any idea ?
I don’t use Vofuria.
Thanks
Can’t get it to work on Xcode 8. crashes when I add:
[self.unityController application:application didFinishLaunchingWithOptions:launchOptions];
with EXC_BAD_ACCESS
Same issue here, did you ever get anywhere with this?
Hii, it working fine for me, what my query is?
before i tapping on the background unity is running. I dont want like that when i tap on the button theonly unity should work.any suggestions please help me.
Someone has understand how to Close Unity when the controller with unityview disappear and restart Unity When the controller restart?