Calling platform specific code and back when game starts
Hi, I just started thinkering with the amazing UE4, trying to getting through all the editor and the programming. I am an iOS and Android developer and I was considering using UE4 to develop part of native apps instead of resorting to plain OpenGL ES X. For now I am focusing on iOS and then I will try to integrate everything with Android NDK. What I need to do is to implement the following logic, for both Android and iOS:
Now, researching on the topic I wasn't able to find anything regarding how to launch the game part of the app after the app has started natively and users have taken some actions. Looking at the UE source, I see that for iOS at least, the engine takes control of the AppDelegate (the entry point of the app), so I assume that if I wanted to override this behaviour and use the sdk libraries I'd have to rewrite quite a big part of the engine itself.
So my approach switched to leaving the app entry point to the engine and launch platform-specific methods as soon as the lifecycle of the game begins, that is:
I found this amazing post on how to call a ViewController from the Engine, but the problem is that that topic refers to presenting a VC in response to a user action. What I would need to do is to somehow "pause the engine loop" and use UIKit/Activities to manage user navigation before the game starts. Problem is: I don't know where should I intercept the lifecycle of the engine as a whole.
I created my GameMode class and set it as the default. I did override the BeginPlay method after calling Super::BeginPlay(). It compiles fine and I can see the iOS View, but I don't know if I am doing it correctly or I am messing up the whole engine logic and I think that the engine is still running underneath while the display shows the iOS GUI.
After this wall of text, my questions are:
Thanks in advance and thanks for creating such a poweful thing - for free! :)
asked Jun 30 '15 at 06:27 PM in Using UE4
Hey! OP here. First of all thank you for your answers. We did manage to integrate both Android and iOS into UE4 about one year ago. Since someone seems interested in this topic this is how we did:
We wanted to use Storyboards and xibs to give a native UI feeling and to ease development, so we created an embedded framework (a library with resources) and we linked it to the UE code during compilation by thinkering with the buildscript (.cs) and ld. This was the hardest part, since there was no documentation available on how to link custom frameworks we had to dig quite deep into the source code. In the native framework we created and compiled storyboards and bundles and we implemented a protocol that we called back from Blueprints and ultimately from C++.
The protocol was in charge of displaying and managing UIKit viewcontrollers from inside the framework. With this approach we didn't interfere with the engine lifecycle. We launched our viewcontrollers from the VC used by UE.
We did exactly as zompi suggested. The engine was "idle" in the background, ready to be shown when needed.
As with iOS, we wanted to use Android Studio and all its goodies to develop the native part. In this case we had to use JNI methods through the Android NDK to intercept the Native Activity that the engine launches by default. We compiled the UE game from Unreal Editor and then imported the resulting binary (the .obb file) and the c libs into Android Studio. From there we rewrote the application flow by showing our own activity on app launch and starting the engine when needed from the JNI.
As far as the implementation goes, in our "game" we implemented an Actor that was in charge of communicating with Blueprints and platform specific code:
The iOS interface communicates with the Actor and uses UE
AndroidInterface needed to obtain the JNIEnv from the engine and then communicate with Android by means of JNI calls. First we get a reference to the game activity, and then we control it from our class and from Java. AndroidInterface.cpp
I posted a working example in this post quite some time ago. If interested there you can find a sample Android project and some more detailed instruction on how to build everything.
Apologies if something is unclear but it has passed more than one year and things are quite blurry.
If more detail is wanted I see what I can get by diggin again into the code :) Hope this has been useful.
Follow this question
Once you sign in you will be able to subscribe for any updates here