Unity window + native iOS window on the same App? - ios

I am building an app for iPad composed of two parts:
a user interface built with cocoa
a Unity scene
And I needed to find a way of integrating both parts and have them communicate with each other.
After a lot of research the best approach that I have found was one based on this tutorial
Basically, I have two UIWindows on my app delegate, one where I keep the hierarchy of all cocoa viewcontrollers and the other is the Unity window. When I want to switch which window is visible I just call [someWindow makeKeyAndVisible]; on the target window. When I need to communicate from the cocoa side to Unity I call UnitySendMessage.
This approach seems to work fairly well in the beginning but as I play with my app and after switching between UIWindows a couple of times, the calls to UnitySendMessage randomly stop producing any effects, the Unity scene stops updating frames and it even reaches a point where the windows don't change anymore and until the app explodes...
Basically, what I would like to know is:
Is this the best approach to integrate Unity and cocoa views? Is
there an 'official' way of doing this? Can anyone point me out an
exhaustive tutorial or sample code?
Being this the best approach, any idea on why does it starts failing
after a while? Do I need to take any precautions when changing
windows? (memory management? Pausing Unity thread?)
Note: I am using Unity Pro, and I have tried both xcode4/ios6 and xcode5/ios7 and the behavior is the same.
Any help would be much appreciated.

The solution we've come to with AteBit is to have the ObjC portion of the application store its data in our SQLite database. The Unity app is constantly polling that database for changes naturally so it is a great fit for a transparent (no pun intended) UI solution.
Separate your UI completely from your data and get yourself some sushi.
Update
Similarly you could use the NSUserDefaults system, which is accessible inside unity using PlayerPrefs.Get# // Set#

Related

Embed Unreal Engine 4 project into another app

I've been trying to work on a proof of concept (POC) where I can embed a UE4 project into an existing application (in my case NativeScript) but this could just as easily apply to Kotlin or ReactNative.
In the proof of concept I've been able to run the projects on my iPhone launching from UE4 pretty easily by following the Blueprint and C++ tutorials for the FPS. However the next stage of my POC requires that I embed the FPS into an existing NativeScript application, this application will manage the root menu, chat, and store aspects of the platform in the POC.
The struggle I'm running into is that I cannot find how to interact with the xcode project generated from the blueprint tutorial and the C++ tutorial generates a xcode project that i'm unsure where the actual root is that I need to wrap.
Has anyone seen a project doing this before and if so are there any blogs or guidance that you can point me to? I've been Googling and looking around for a couple weeks and have hit a dead end. I found a feedback post here from April of 2020, that was referring to a post in January 2020 that talked about how Unity has a way to embed into other applications additionally a question from 2014 here. But other than that it's a dead end.
A slightly different approach
Disclaimer: I'm not an UE4 developer. Guilty as charged for seeing an unanswered bounty too big to ignore. So I started thinking and looking - and I've found something that could be bent to your needs. Enters pixelstreaming.
Pixelstreaming is a beta feature that is primarily designed to allow for embedding the game into a browser. This opens a two way communication between a server where the GPU heavy computations happen and a browser where the player can interact with the content - the mouseclick & other events are sent back to the server. Apparently it allows some additional neat stuff, however that is not relevant for the question at hand.
Since you want to embedd the Unreal application into your NativeScript tool(menu of some kind if I understood correctly), you could make your application a from two separate parts:
One part would run the server.
The second part would handle the overlay via the pixelstreaming.
This reduces the issue of embedding the UE4 into an application to the(possibly easier) issue of embedding a browser into your application. (Or if your application is browser based - voila, problem solved.)
If you don't want to handle the remote communication, just have the server-side run on the localhost.(With the nice sideeffect of saving bandwidth.)
Alternatively, if you are feeling adventurous, you could go and write your own WebRTC support on the application side to bypass the need for the browser alltogether. It might not be worth the effort though.
Side note: The first of the links you provided is a feature request which hints at the unfortunate fact that UE4 doesn't support embedding. This is further enforced by the fact that one of the people there says somethig along the lines "Unity can to this, it would be nice if UE4 could as well."
Yet a different approach:
You could embedd and use a virtual display to insert the UE4 part into your controller - you would be basically tricking UE4 into thinking that the desired display device is a canvas inside your application.
This thread suggests a similar approach:
In general, the way to connect two libraries like this would be through a platform dependent window handle, e.g. a HWND under Windows. Check the UE api if you find any way to bind the render target to a HWND. Then you could create a wxWindow in wxWidgets and tell UE to render into that window. That would be a first step.
I'm not sure if anything I've listed will be of much help but hey, at least I tried :-). Good luck with your game.
At the same time, the author suggests to:
Reverse the problem:
Using the UE4 slate framework and online subsystem. You would use the former to create the menus you need directly in the UE4 and then use the latter to link to the logic you want to have outside of the UE4. However that is not what you asked for so I'm listing it only for the completeness sake.

Today’s Extension Using SpriteKit

I'm trying to make a widget game, is it possible to use SpriteKit within a Today Extension?. I've been searching for similar posts but I've only found a question related to using SpriteKit in a AppleWatch extension.
I also working on some game in the today screen. So far I have found 3 solutions which working solid:
Like mentioned working with UIKIT
Use SpriteKit in a minimal way
Using offscreen images for rendering
The problem on solution 2 is, that it's very unreliable. Even calling regularly completionHandler!(NCUpdateResult.newData) has not worked.
So it's just the limited usage of SKAction at the end which has bring a lot.
Solution 3 is also good and works quite solid. Of course you must reinvent the wheel and can not use the nice features of SpriteKit. But because I've used this approach already in watchOS games, it was not much effort to use in Extensions.
I recommend solution 3 because you have full control and it works solid.
It is definitely possible. I think you are aiming to build something like the popular "Steve" Widget Game, and I believe that is a SpriteKit Game built into a Today Extension.
To begin, I would suggest to fully understand Today Extensions and it's limits and then fully understanding SpriteKit and the limits that it has.
Something you really want to focus on is making an extremely efficient piece of app. All around, from the actual code and how your code runs. This is due to the fact that Today Extensions are not really apps but "extensions" to your device so if you have a game that is graphics intensive or memory intensive, your app will crash.
I tried develop game in spriteKit for ios today extension, added SKViews to UIView, but it did not work. It seems like scene not loading in today extensions. I think it is not possible - use spriteKit in today extension. But i found good solution - using UIKit instead spriteKit. It is very powerfull framework for game developing, and i think Steve game developing via UIKit. You can check adding dynamics via UIKit in this sample: https://www.raywenderlich.com/50197/uikit-dynamics-tutorial
Also i can upload sample of using UIKit in today extension game developing on github if needed.
I made a framework with the intention to solve this problem some months ago, link here. I haven't had time to test it properly in iOS 11, so there might be some new bugs.
The only working solution I found to use SpriteKit with Today Extensions was to create the SKView and present the scene in viewWillTransition(to size:with coordinator:). This is necessary because Today Extensions have a different life cycle than a normal application, look at these iOS Widget Gotchas to get more detailed information on how this works.
EDIT: The correct method to setup these things might now be viewWillAppear in iOS 11, but it might be necessary to do some testing.
Another really important thing to consider when creating widget games is that you have very little memory(16mb if I recall correctly) to build your game with. You have to reduce your memory usage at all costs, otherwise the widget will crash and display a message telling you that it was unable to load.

Xcode (swift) vs Unity for isometric 2d mobile-apps - Performace, Package Size

Let's assume I want to develop an isometric 2D mobile-game such as Clash of Clans for example.
My main target would be iOS but of course Android would be nice, too (but not a must-have).
Now I have to decide to either program with Apples XCode (therefore Swift as a language, which I am already pretty familiar with), or develop my game with Unity3D (and therefore C# as a language, which I am also pretty familiar with).
Personally, I don't prefer one over the other.
So much for the set-up.
As I don't have any preferences, I'd like to choose the one that offers the most benefits for my 2.5D game to me.
The questions:
Is there a difference in getting an approval for the App-Store if you program in Swift, or use Unity; C#?
How big is the difference of the published package-size of the app between Unity and XCode?
Does my Unity-written app run as smoothly as my XCode-written app?
I hope you could help me with that.
If I missed some points there, feel free to criticize me and give me your opinions on it.
Greetings
Chriz
Is there a difference in getting an approval for the App-Store if you program in Swift, or use Unity; C#?
No, given this general comparison - there should be nothing here favoring or disallowing one over the other.
How big is the difference of the published package-size of the app between Unity and Xcode?
That is very hard to say. There will be added libraries for Unity inclusion whereas Apple would already have shared libraries apart of the OS - used by every app. Think shared libraries here - only Apple is permitted to do this. Not to be confused with the to be newly released iOS 9 'App Thinning'.
The larger weight will be media/images/bitmaps.
Does my Unity-written app run as smoothly as my XCode-written app?
Since they both end up using OpenGL, the end result should be the same or very similar. Obviously as the OS and device mature - if Unity doesn't leverage it, they could end up giving up performance advantages.
But... the flip side of being so tightly coupled with Swift/iOS/Apple, is you abandon your Android market - and if you are even considering it - I'd suggest Unity based on what you shared if there is a remote possibility you want to deploy to Android, desktops, *TV devices in the future.

iOS: Communication between Game module (within an app) and rest of the app

My team is working on an iPad app that includes a gaming module (could be 2D or 3D). We intend to develop the gaming module using one of the Game Engines and are currently evaluating
Unity3D
iTorque2d
and OpenGLES.
Now this gaming module will be interacting with other parts of the app (the way we see it is that there will be a common SQLite database accessible to both the gaming module and rest of the app). However, from our initial evaluation it seems that most gaming engines either do now allow this or it is quite tricky to handle it.
Can someone share their experience in case they have tried something similar?
We have been working in a very complex system with graphics, html (don't ask, not my doing), and with normal UI. Our biggest issues were:
Dealing with context issues in the database--making sure objects were being accessed from the proper context.
Handling the slow loading bloated size of the tubby Unity engine. Its so big, that you hate having it in there if you don't need it, but so big that you don't want to have to reload it when switching back and forth with it.

How to make an iOS app start where it left off

I'm making an iOS app through UIStoryboard mode and I wanted to know if there was a way to add something so when the user leaves the application, it'll continue where the user left off next time he launches the application.
By the way, I'm making a simple UIStoryboard application like I mentioned earlier that only has simple pages.
Thanks!
Check out this section in the documentation where Apple briefly touches on this topic.
Preserving the State of Your App’s User Interface
I think this is the general idea of how you would do this, the Three20 framework does this by using URLs, you may attempt to adopt this design as well. This is not to say you should USE Three20 but you can gain some ideas from seeing how they solve this problem.
Persistence in Three20 Framework

Resources