Courtesy: This post was first published on medium.

 

Yeah you read that right. I’ve been working on an app for mobiles with unity. I know it sounds hilarious. Game Engine for an app? Well hear me out.First of all there were a few fundamental requirements in the app.

Obviously for AR functionalities Unity is by far the best choice if you ask me. Do tell me if I’m wrong about that. But for Cross-Platform Development we have lots of other candidates.

  1. Flutter
  2. React-Native
  3. Xamarin
  4. IONIC

Lets go through a very simple comparison chart.

Comparison among React Native, Xamarin, IONIC, Flutter

 

I crossed out IONIC from the start as the performance was low. So I ended up with this list.

  1. Flutter + Unity
  2. React-native+Unity
  3. Xamarin+Unity
  4. Unity

Research Phase

 

 

After doing some research I couldn’t find any proper resource to embed unity with Xamarin. So I crossed it out. I found out React-Native and Flutter both had the capabilities to embed an unity player. I’m not really a fan of JS so I gave flutter more priority. After doing some detailed research I found out the unity widget for flutter was still in development and it didn’t support iOS yet. Since it doesn’t support iOS. I need to cross it out too. I was left with React-Native only now.

Then I thought. Why should I combine two bad choices together for an APP development when I might be able to do it with just one? 
Unity is a game engine. So imagination is the limit. I went through the requirements all over again to see If there’s anything that can not be done with unity? Well one other requirement was to show ePUB files on the screen. At the moment I had no clue what it was. Googled a bit about it. And tried to find some easy way out. Well there wasn’t any open libraries that would have done the job. So I decided to make my own if necessary[I didn’t have to in the end].

Choosing to use just unity seemed like a wise idea to me. Because I’ve to think about only one technology stack through the development cycle. Also I reduced some build time and size. Talking about size you must be thinking how big the apk or IPA would be with unity. If it was 2017 I’d never have dared to take this step. But Unity has come a long way. Now we can easily take out the packages that we don’t need. For this project. I only needed the UI elements and some web elements other than that I stripped everything out. And finally the APK was down to 10mb. I was satisfied with the number because if I did follow the React-Native + unity Route , The final size would be 10mb+4mb(react-native binaries) At the bare minimum. I eliminated that.And I did have a reference application which was way above that. Around 50MB(It was a native app,but had too much static content). I was clearly in the Safe Zone.

Development Phase

 

 

 

 

 

 

 

 

 

 

 

Tips

 

  1. Constant Update: This is the most important optimization to keep in mind while making an app with Unity. Unity provides a constant update loop by default. It’s easy to use it even by mistake without knowing the cost. Do not use any of the UPDATE functions in unity. This functions run every frame or after a fixed time which is like 0.1s or so. This is certainly bad for normal Application that has no reason to utilize such power. Do not write any code in Update function.
  2. Strip Engine Code: Unity does provide a bool check to strip unused engine code. But I’d recommend using the New Package Manager introduced in 2018 to uninstall unnecessary modules for application. This will do more or less the same thing but you will know exactly what you are doing having full control.
  3. LWRP: The new scriptable rendering pipeline allows you to optimize the rendering to a next level.[I didn’t use it yet as it’s still experimental] The new LWRP features a 2D Rendering path. This basically removes all those unnecessary 3D rendering power from the build. Which means you can get a step closer to downsizing your application.
  4. Async Or Co Routine: Since Unity has support for C# 7, you can certainly use the power of ASYNC methods. This will certainly increase your performance in code that needs WEB API calls. Alternatively you can implement Co-Routines smartly to get the same output.
  5. Input System: Game Engines have a bad reputation for not being event based. The new input system is event based and also optimized. Although as far as android or iOS is concerned there won’t be much of a significant performance change.
  6. Project Structure: Since Unity doesn’t give you a default folder structure. This is both good and bad. If you don’t know what you are doing, You are certainly going to mess up the files in the project. You need to plan and organized your files sincerely . This applies to game development as well. Always keep things organized and tidy. Things will go out of hand really fast if you don’t.

 

 

 

 

 

Sounds Cool Right? Planning to develop your next cross-platform app on Unity? Well hold your horses. This application was only legit because there was an unity dependency. And no matter which route I went for, I’d be adding unity’s weight over some cross-platform tech. So this is the only reason choice of this stack was legit. Otherwise, I still won’t recommend developing Apps with Unity unless you need to have AR features in it. Because the Build size is no way fair. If it was 2017 the minimum build size would have been 20mb at the very least. But Unity is being built up from the ground and everything is being turned modular. So certainly in the not so distant future you can definitely consider using unity for developing cross-platform apps. if you are thinking about monetization you can use ad’s sdk made for unity(yeah official packages). But if you are planning to use some kind of payment gateway, There’s no official support. You can certainly try to make your own. Or Use an web-view maybe. If your application is animation heavy unity is a great choice. Still if you are making a basic application that has nothing to do with AR don’t choose it. Because all the size overhead is not acceptable yet. Because you can get under 5mb with Xamarin,Flutter. Where unity only gets 10mb now. If you are willing to add 5mb for the rapid development , This could be a good idea. Because as far as performance concerned, It’s a game engine. And you get performance by default. I did notice quite a few performance increase in heavy UI animations on the unity application. If you are targeting lower end devices, this will certainly be a issue. Games are power hungry. Even after all the optimization they need more power than some random application. So obviously there’s a significant power difference between native application and a unity application. at 2019 you can almost ignore this. Because the significant power difference would be like using 10mb of more ram usage over native or the batter will drain 1–2% faster I don’t think there will be any significant processing power difference. Once upon a time that was certainly a big issue. Also since we are talking about Cross-Platform. There is certainly some downside to it. If your application needs to run some native code, You would need to write some extra wrapper classes for it. Well in that case You should ask yourself if you really need a cross-platform application. Because If you really need to make system specific calls do you really need a cross-platform app?

Since unity is being supported by .net platform. You can use any libraries from .net . Anything that you can do on .net, You can do in unity. And .net has a very wide range of state of the art libraries. Depending on the requirements I’d choose to develop cross-platform apps again.

First published post link: https://medium.com/brainstation23/what-i-learned-while-developing-an-app-with-unity-a56fe567a9ce