Our Unity Tutorial on Augmented Reality Game Development with Vuforia SDK

Unity AR Tutorial: Augmented Reality Game Development with Vuforia

 

Vuforia is an AR platform that provides amazing opportunities for augmented reality development. Here are some examples:

Vuforia also has a Unity SDK and in the second part of this tutorial  I’ll explain how to integrate and develop it. But let’s start with the Vuforia integration…

Obtaining a Vuforia license

add_license_keyThe first thing you have to do is  register on Vuforia page. After you complete the registration process, you can start developing with Vuforia SDK. You will then need a license for your project.

Head over to the Development tab, and click on the “Add license” button. A little form will show up. Fill in the form as shown on the side and click “Next”.

Then you have to confirm your license key by agreeing with terms and conditions and by clicking “Confirm”. Pretty simple so far, right?

Vuforia’s Unity SDK

It’s time to download the Vuforia SDK for Unity. You can download it in the Vuforia Downloads tab.

unity_sdk

After downloading the package, import it into the existing project inside of Unity.

Prepare the markers

Now it’s time to prepare the markers. Markers are the images that Vuforia will use as the points of reference to display your objects. The more distinct key points the image has, the more accurate or “augmentable” your markers will be. The easiest way to create such  marker is to generate a QR code. QR codes have a lot of key points and they work like a charm. You can generate them yourself or, to make it quicker, you can download mine 🙂

create-databaseOnce you’ve got the marker, it’s time to upload it to Vuforia. Go to the Vuforia Target Manager page and click on the “Add new database” button. Type the preferred name for your database and choose the “Device” as a Type option.

 

Great! Now, select the name of the database you’ve just created and then click on the “Add the new target” to the database.

add-target

Select the Single Image type, pick the marker you’ve downloaded before, set the width to 1, name it the way you want it and click “Add”.

There are other types of targets, for example Cuboid, Cylinder or a 3D object. These can work as 3D markers (you can make them if you feel like it), but preparing them would take a lot more time, because you’d have to create and upload every side of that cuboid to Vuforia and that’s a chore…

Alright, so now you can see your target has been added to the list and it’s ready to be downloaded. Click “Download Database” and import the package to Unity.

Preparing the scene

Setting up the scene is also very easy. Get rid of the existing camera on the scene. Vuforia has its own camera that your scene will use. Drag and drop ARCamera prefab from Vuforia > Prefabs folder into the scene. Your scene hierarchy should look like this:

unity-scene-image

Now, let’s setup the ARCamera properties. ARCamera prefab requires the license key which you can find on the Vuforia License Manager Page.

AR license key

Copy and paste your License key to Vuforia Behaviour Script field of the ARCamera prefab on the scene.

unity-scene-with-script-image

Select ARCamera in your hierarchy, and in the Database Load Behaviour tick the “Load [name] database” checkmark, then “Activate”.

database-load-behaviour

Setting up the markers

Alright, now it’s time to add the markers on the scene! You can do it by dragging ImageTarget prefab from Vuforia > Prefabs to your scene.

Your ImageTarget needs to be set to a specific marker image. It has a script called “Image Target Behaviour”, where you can do that by choosing your database name in the “Database” field and then select the “ImageTarget” from the drop down list. It should look like this:

image-target

Great, you’re almost done! Now it’s time to add some objects to the display. Right click on the ImageTarget in the hierarchy, 3DObject > Cube. Resize the cube the way you want it and the project is ready to be compiled! Alternatively, you can add any 3D object to the hierarchy of the ImageTarget.

As you can see, Vuforia SDK is very easy to setup and it has a lot of nice features you can utilize to make awesome games or apps. For example, you can combine a couple of those markers to make something a bit more complicated like this:

Procuring Graphical Assets

You will need some 3D models. I’d suggest that you download and import these amazing drone models by Popup Asylum.

Next, we’ll need a QR code as an additional marker. You can generate your own, but feel free to use mine if you’re lazy 🙂 Also don’t forget to upload it to the Vuforia Target Manager page and download the updated database after that.

For the testing purposes you’ll need these two markers printed, so I’ve also prepared a pdf for you to download.

A few more textures for you to import: drone_shadow, white_ring.

Scene setup

Drag and drop 2 ImageTarget prefabs from Vuforia > Prefabs to the scene. Name the first one as “DroneTarget” and the second one as “GoalTarget”. After that assign the corresponding “Image Target” to each one of them in the Image Target Behaviour Script. In the same script, change the width of the DroneTarget to 3 and GoalTarget to 2. It should look like this for the DroneTarget:

dronetarget

And like this for the GoalTarget:

goaltarget

Now in the ARCamera object in our hierarchy, head over to the Vuforia Behaviour Script and change the value of “Max Simultaneous Tracked Images / Objects” to 2. Then in the “World Center Mode” section select “SPECIFIC_TARGET” from the drop down list and in the section “World Center” choose the DroneTarget from the hierarchy. It should look like this:

ar-camera

Connecting Models to Markers

We’ve got the markers, let’s add the 3D models they will represent…

Right click on the DroneTarget and select “EmptyObject”. Make sure this new object has a position of [0;0.5;0] and scale of [0.33;0.33;0.33]. I’ve also changed the name of it to “Drone”. Then, add a 3D model of any drone as a child to this object and change the position of it to [0;0;0] and scale to [0.33;0.33;0.33]. Now the hierarchy looks like this:

drone-model-setup

So, let’s add a model for our GoalTarget. Add an empty object same way we did for the DroneTarget and change its name to “Ring”. Then add a Sprite Renderer to that object and in the “Sprite” section, choose our ring sprite. After that you can change its color to whatever you’d like. You also might want to resize it, change the position to make to fit the QR marker. It kind of looks like this for me:

all-model-setup

Nav Mesh setup

Alright, so we’ve got the scene, let’s now get to the main functionality… Pathfinding. So we need to bake a Nav Mesh. For more info, please, go to Unity navigation tutorial page.

Baking a Nav Mesh requires a presence of a regular mesh on the scene to walk on first. Right click on the hierarchy 3D Object > Plane. Rescale the plane so it covers an area around the markers where you potentially would like your drone to move. Now open up the navigation window (Window > Navigation) and in the Object tab make sure your plane is selected along with a “Navigation Static” checkbox. After that click “Bake”. Fantastic! If your scene looks somewhat like this, you’re on the right track!

navmesh-with-plane

So what do we do with that annoying white plane obstructing the view? Well, it’s time for us to get rid of it. Yeah, just delete it, we won’t need it anymore, since the Nav Mesh is already baked.

Once we’ve got our Nav Mesh, it’s time to setup a Nav Mesh Agent, an actor that would travel using the Nav Mesh. The Nav Mesh Agent functionality should obviously be applied to the drone, so select the first child in the “DroneTarget” hierarchy…

select-the-drone

… and add NavMesh Component to the inspector. You’ll see a whole bunch of parameters for this component. I’m not going to explain what each and every one of this parameters means since that’s not the point of the tutorial. (If you’re interested in the commentary over the parameters, please watch this video and here’s Unity docs). Here’s a screenshot of my Nav Mesh Agent parameters for the drone:

nav-mesh-agent

Coding time

The initial scene setup is ready and it’s time to write some code for it to work… Create a script in one of your folders and add it to the “Drone” object (DroneTarget first child).

The whole moving mechanic is pretty simple. We’d need two variables variables:

A function to track a position of the second marker and move the drone towards it:

That’s it. Just execute this function in the update and don’t forget to select the “Ring” (GoalObject child) object as a public variable in the inspector.

movement-script

You can now build the project onto your phone and check whether it works with the markers.

NOTE: The DroneMarker should always be in the camera view for the whole app to work since we’ve declared it as the world center and the whole drone logic is attached to it.

Drone leaning

You might also want your drone movement look more realistic, so let’s add movement leaning. The done will lean forward depending on its current speed.

MapRange function

There’s a great function I use pretty often called MapRange. It converts numbers within a range to numbers within another range depending on the current value.

A simple example of this function working is… let’s say we want to change the color of the ball depending on player’s distance from it. s would be our current distance from the ball. a1 – minimum observed distance, a2 – maximum observed distance. So we want the ball to be blue if the distance is more than 3 meters and red if player is 1 meter away or less. everything in between would be automatically purple -ish. So the implementation with MapRange would look like this:

playercolorball

Back to the drone leaning…

so in case of movement leaning, exploiting MapRange() would be this simple:

Add PitchCtrl() to the update function and you’re good. The drone will lean forward while moving.

Shadow

Let’s add a shadow to the drone. A simple static shadow. That’s a piece of cake since we just have to add a sprite to the existing hierarchy. Make sure your shadow object is the second child of “Drone”. Just like that:

first-shadow

Line renderer

In order to setup a line renderer we should add a sprite, but don’t worry, there’s no need to import one, just head over to your project window and open the folder where you store your sprites. Hit Right click > Create > Sprites > Square. You’ve got your new sprite which we’ll use for the new material that we’re about to create.

Right click > Create > Material. Material’s shader should be changed to Particles > VertexLit Blend and Particle Texture to the earlier created Square sprite. Sounds hectic, but just look at this picture and you’ll get it:

laser-material

Create a new script. Let’s say the name of this script is Goal. Attach the Goal script to our Ring object.

ring-line-renderer

Also attach line renderer component to the “Ring”. Line renderer would require a material, so please add the material we just created to it.

line-renderer

So, it’s time to write the code, which is also very simple. Here the whole Goal script code and it’s pretty much self-explanatory:

If you run the app now, you’ll see the ring’s line/laser pointing to the drone destination. It’s great but we can also make this destination look a little bit more clear by adding another object… Just a game object containing a Sprite Renderer and Animation components.

destination play

Create a public variable destSprite and update MoveToTarget() function.

That’s it, run your project on a smartphone and you’ll have the same result as in this video:

Thanks for reading and don’t forget to subscribe to our newsletter not to miss any of the new Unity development blog posts!

Becoming a Unity Asset Store Publisher

You’re now in process of creating your game. Did you make something that could be used again? Is it something that is not easy to build and can be useful for others? That’s great! Sell it on the Unity Asset Store!

Before we start

There are at least two kinds of publishers on the Asset Store. The ones that belong to the first type are people who are creating their content solely for the purpose of selling it. Those people are mostly focused on quality, documentation and support. The second group are game companies that are building assets for internal use but then eventually they are publishing them to the wider audience. Their assets are made for specific games but sometimes they can be reused if the quality is good enough.

It’s more difficult to make money out of artistic assets (models, music, textures) than of script and editor extensions. I don’t know the exact numbers but this topic was frequently discussed on the publishers’ groups. The reason why is that artistic assets, no matter how good they are, are difficult to re-use. Sure, there are environment packs and character packs, but most of the times there will be something missing, something that you’d like to see in your game as a game creator. Mixing multiple models and textures together rarely looks good enough, so many developers decides to hire 3D modelers and graphics designers on their own.

This issue does not affect scripts and editor extensions that much. Scripts can be very flexible and it only depends on good design and amount of time spent on working on it.

How to create a successful script

Many people were asking me if working solely as Asset Store publisher is profitable. It really depends on the products that you’ll be releasing. Some products will be more successful than others. Success is something that may be difficult to measure. For me a successful product is something that I did in relatively small amount of time, it does what it is meant to do, it sells and does not require too much maintenance or support. Some of the best unity assets are those that act as features that the Unity editor itself should include natively.

One example of a successful product is Energy Bar Toolkit – a script for health bars set up of different kind. It does what it is meant to do and it does it well. The good thing about EBT is that for most of my clients this asset offers more than enough. An example of an asset that is not very successful is Mad Mesh Combiner. The idea was quite good, because many Unity developers were struggling with the frame rates on mobile devices due to the big number of draw calls. Unfortunately, I did not predict how much time it would require to make it work properly in most cases. Also, my clients didn’t understand the limitations and many of them were blaming me after purchasing the asset instead of reading through the instructions first.

Generally speaking, think of creating assets that have a clear definition of finished. At least for starters, because it’s easier to become a publisher if you can release more than one product in a short period of time.

Uploading your first asset

So you’ve decided to become a publisher. Brace yourself, there’s a lot to read if you want to handle it all. The best resource is an official guide to how sell assets. Please make sure to read all the listed documents. Read and remember the Submission Guidelines – making it right will surely increase your chance of getting approved.

Make sure that your asset has a decent documentation. For the first version you can do a PDF file generated out of Libre Office document, but as your asset will grow the documentation may become bigger and less coherent. Consider building a HTML documentation with Jekyll. Jekyll is like wiki, but it generates static html files that can be sent to any http server or zipped into a file and distributed along with your asset.

Prepare a decent presentation, but do not spend too much time on it – you can easily append it later! YouTube video is a must-have, having a WebGL demo will help too. Don’t worry too much about the icon and product page background. It’s not as important as you may think.

Do not upload your assets using the latest Unity version available – users of older Unity versions won’t be able to use them. Usually only a newly created games use the newest Unity version. After that, their creators stick to that particular version until the next game. If there’s a significant change between Unity versions that you cannot ignore, you’re allowed to upload your asset from multiple Unity versions. Thanks to this your customer will receive the content that will closely match his setup.

Don’t worry if you get declined for the first few times. Unity guys are very friendly and helpful with getting your asset right. Usually it’s a matter of something that you’ve missed while preparing it for the upload.

Your asset is now online!

After getting approved, set up a forum thread about your asset. It’s a method of marking your presence. Many of your clients will also use it to get the support. It’s a preferred way of providing support, because when someone will search for issue that someone else had, most likely he or she will find one of your answers.

Make sure to reply to all of the email support requests. Even if you don’t know the answer or you’re not planning to add a requested feature the worst thing you can ever do is to ignore your client.

How would you know if a person that is writing to you is your client? You can ask them anytime for order no. (it’s on the invoice). On your publisher panel you can find a verification tool. If the Order No. is OK, you see your asset name, purchase date and for what price it has been purchased.

You can give away up to 12 free copies of your asset a year. Make use of that! I did it when I had released my initial version and I needed some feedback. I gave few away to some people on the forums and I’ve got a great feedback that helped me to improve my tool before the next release.

Then what?

As I said before, it’s difficult to measure a success. Think of releasing at least 3 assets. When you do, you will know enough to evaluate which one is a better investment.

Subscribe to Unity Blog. Stay up to date with the latest features. Test your assets on beta versions before releasing them. You can sometimes find yourself in a situation that new Unity version will break your code. This is your best chance to submit a bug report and get it fixed before it goes public. Trust me, it can save you from a lot of trouble.

If you’re already a publisher or if you want to become one after reading this article, please share your thoughts in the comments!

Links

JetBrains Rider, an alternative IDE to Visual Studio for Unity C# Development

JetBrains Rider: An Alternative to Visual Studio

For quite a long time, Unity installer came with a custom MonoDevelop distribution to assist Unity developers with starting with game development. At that time, it was the only available option for many, since other solutions were simply too expensive. Visual Studio Community was then introduced, and almost immediately it became the default Unity C# IDE, but only on the Windows operating system family. It seems like quite soon we will have another player on the market and its name is JetBrains Rider.

.NET enslaved by Windows

It’s not surprising that the language created by Microsoft works best on Windows operating system family. It seems that even Microsoft is surprised by how .NET got so popular these days. It’s a bit of a problem, because today we’re entering a new era in which Windows is no longer a dominant operating system in the world and .NET is widely used on variety of platforms thanks to Unity. If Microsoft wants to keep .NET position and profit out of development tools, .NET must become a cross-platform framework for real.

The first step of becoming more open to multiple platforms was introducing .NET Core (wikipedia) – the first open-sourced .NET implementation. Then Microsoft introduced Visual Studio Code – the first editor with “Visual Studio” in name that works on MacOSX and Linux. Still Visual Studio Code is “only” a GitHub Atom fork. It’s a great editor, but it’s nothing when compared with original Visual Studio IDE running on Windows with ReSharper onboard. Speaking of which…

There’s a new player in the game: JetBrains Rider

There’s a market gap for sure – more and more developers tend to use Mac OS X or Linux as their development platform and beside Visual Studio Code and MonoDevelop (which is good, but not so great) there was nothing worth considering until recently.

JetBrains is a Czechia based company known for the creation of a great Visual Studio extension called ReSharper, and IntelliJ IDEA (IDE for Java developers). It seems like they’ve recently decided to merge those two.

JetBrains Rider is a cross-platform .NET IDE based on the IntelliJ platform and ReSharper. If you don’t know either one of those, then consider this as a great opportunity because learning these two tools will change the way you work with your code forever. Do I need to tell that it will increase your productivity? Yes, it’s a buzz-word, but it’s true! What is more important, it will make your work easier and you – happier.

How valuable is your time?

Do you value your time? How much time do you spend on writing easy but bloated code and how much on focusing on problems that matter? ReSharper is a tool that helps you to get through the parts of the code that are not requiring too much of your brainpower. It consist of powerful generator and refactoring methods that will assist you on demand. It also includes code analyser that makes sure you won’t make any simple-to-prevent mistakes. Besides that, it just tries to be smart and friendly to a developer.

Rider comes with native Unity plugin! It does not only make it aware of *.meta files, but also know MonoBehaviour specific methods like Update(). Thanks to it you will see a code-completion of these methods and you won’t be seeing any warnings about unused functions.

It’s even aware of Unity-specific optimizations like tag-comparing:

And maybe it’s not that important, but it also shows how Rider developers are getting into details – colouring of Color struct constructor:

Yeah, your guess is right! It shows you the actual defined color!

I won’t make a complete list of ReSharper features, because there’s just too many of them. Instead, please browse the documentation. There’s a lot of great and simple to understand examples out there.

Still, it’s important to mention that Rider, by contrast to Visual Studio Community and Visual Studio Code, is not free. Actually, it is distributed via Early Access Program which now costs nothing, but it’s justified to believe that Rider will be using a subscription payment model. For many people this information would be a no-go, but consider whether it is worth it – it can increase your productivity (in my opinion quite a lot, if you get to know it well).

But I’m happy with my Visual Studio on Windows!

I’m also a satisfied Visual Studio user on Windows. Why changing it then? The reason may be quite simple, take me for example. I’m working on Windows about 50% of time. Rest of it I spend on my MacBook and Linux Mint. On all three I sometimes need to do something in Unity. The real pain is that I have to use totally different IDE on all three platforms since Visual Studio Code for some reason does not play well with Linux (some strange mono issues) and I had to use MonoDevelop there. I’m really looking into Rider to get out from EAP to use it constantly on all of my 3 development platforms. And even now, while it is still in early stage, it works really, really well! Yet, if this scenario doesn’t fit you at all, I still encourage you to try it!

Conclusion

Rider is a fresh approach to .NET development. It focuses on developer’s productivity, happiness and it is aware of current market trends, which makes it an interesting alternative to Visual Studio.

JetBrains reader can be downloaded for free from its home page. Each version has a expiration period of one month. New versions are released at least once a month so until Rider is still in development, you will be able to work with it without any costs.

I strongly encourage you to learn as much shortcuts as you can – this IDE has been created for those who favor keyboard over mouse. If you don’t know the shortcut that you’re looking for, try hovering over an option to see a tooltip that often will tell you wanted key combination or try pressing shift twice to open Search Everywhere popup. It allows you to search through all of the Rider actions.

Optimize yourself! [Part 2]

Things you can do better in Unity!

This is the second part of our tips list, that can help you increase your productivity with Unity.

The first part can be found here. So definitely check it out if you haven’t already!

1. Unity project setup wizard

When you’re creating a new project it often takes at least half an hour to setup everything. There are at least 2 ways for you to save time here:

  1. Simple: create a project template with basic setup, folder structure and version control ignore file. This will be the most efficient one to make and you can put stuff in it already. But it is not the most customizable one, so probably you will need to spend this additional time on finishing your configuration.
  1. Advanced: create a module that will be responsible for setting up your whole project in a way you want it. With as many game/folder structure/architecture variants as you’d like to have. And in a perfect world, it would be great to have such module but it takes time to make it.

No matter which option you choose, it is always helpful to have a solid foundation for you project 😉

2. Finally you drag the list of objects into the component

Sometimes you may come across a case where you have to fill the list of objects with objects from a scene or a project. When you’ll first try to select all of the objects you’d like to assign, you’ll realise that Inspector is no longer showing you object with your list to fill. There is a very simple solution to that, and not many people know about it.

In a top right corner of Inspector there’s a lock button, that locks Inspector focus on current view.

Now you can select as many objects as you like and you can easily drag and drop them all into the list in Inspector.

Done!

3. Use build-in json tools

Normally, when you are working with JSONs, you have to have JSON parser. After parsing a string into JSON object, you have to assign all the values from JSON to the desired object, which is super boring to write each time…

However, since the Unity 5.3 they gave us built-in JsonUtility which will do most of it for you!

Warning: JsonUtility currently works only with ‘structured’ JSON and does not support types, like dictionaries. If this is a problem for you, then you probably need to find a fully-featured JSON library.

For more information about JsonUtility you can go to: https://docs.unity3d.com/Manual/JSONSerialization.html

4. One script that handles all of the platforms?

If you are new to programming, you probably don’t know much about platform dependent compilation. If you are into programming, then you have probably seen a code that uses platform dependent compilation a few times, but you might not understand how it works. It’s simple! It gives you the power to write the code that will be executed only on a specific platform. So you might ask why it’s good to use it? Because you can use libraries designed only for one platform.

For example: you are making the greatest game of all time for Android and iOS. And you want to implement that last feature, namely leaderboards. You’ve created a button to show these native leaderboards and assign method OpenMainLeaderboard() to it. And now it’s time to implement this method, but how will you run Google Play Services on Android and Game Center on iOS?! That’s simple! Use platform dependent compilation!

Example:

With that you don’t have to worry about the missing references from libraries that are not designed to run on other platforms.

If you’d like to find more platform directives go to: https://docs.unity3d.com/Manual/PlatformDependentCompilation.html

5. Don’t waste your time for reimporting project over and over again

Aren’t you tired of waiting for your project to be reimported each time you change build platform? For me it’s not only boring, but also wasting a lot of time! But there is a mighty solution for that, which no one ever told you about!

In Unity there is something called Cache Server. It can be configured to work on your local machine or on a dedicated server. This cache server will save your reimported assets and when you change your build platform, it will give you back your reimported assets, so you don’t have to reimport them again! This is great! And the only thing you have to do is to go to Unity > Preferences > Cache Server and change Cache Server Mode to Local or Remote.

You can read more about Cache Server on our blog:

http://blog.theknightsofunity.com/using-unity-cache-server/

http://blog.theknightsofunity.com/unity-cache-server-localhost-make-sense/

Summary

That was top 10 things that you can do better in Unity (with those in the  previous part)!

I hope that this list will help you save a little more time that you will still waste by watching another cat video on the internet 🙂

If you have your own trick to speed up your work, then don’t hesitate to share it in a comment section below.

And don’t forget! Optimize yourself!
You can also subscribe to our newsletter, so you won’t miss our posts in the future!

Optimize yourself! [Part 1]

Things you can do better in Unity!

How many times you’ve been bored or annoyed because of some stuff you had to do over and over again? Probably countless… But fear no more!

Bill Gates once said “I choose a lazy person to do a hard job. Because a lazy person will find an easy way to do it.”.

And you might ask why even I’m bringing this quote here? It’s because I am going to make you lazy in a good way… 😉

Let’s get it started

The main reason we came up with idea for that list is the fact that we (as  humans) are lazy by design and we don’t like to repeat ourselves in our daily tasks. As a  result, we came up with tools and tricks that we use to make our life easier and we hope to make it easier also for you!

So here are top 10 things you can do better in Unity:

1. Change your play mode editor color!

How many times you’ve been tweaking your game to be in this one perfect spot? And all of a sudden you realized that you just clicked on pause button and lost all of those changes? Of course this is how Unity works, but how many times you forgot about it? Probably not only once. 😉

So the simplest solution to remind you that you’re in the play mode is to change editor’s play mode color! To do so, just go to Unity > Preferences > Colors and change your Playmode tint color to something more vivid.

Results?

2. Let the code write itself

There are many tools that can extend your IDE and give you just a little bit of support for your programming skills. One of such extensions is JetBrains ReSharper which is so useful that you probably won’t want to program anything without it.

This tool analyzes the code for you. This tool writes the code for you. This tool finds bugs for you. THIS TOOL EVEN FIX THOSE BUGS FOR YOU! Maybe not all of them, but it fixes the typical ones without any problems 😉 If you are programmer then you should definitely check it out.

Here are some examples:

  • Converting code to Linq:

  • Converting code from Linq:

  • Adding missing usings:

  • Generating methods:

Home page of ReSharper: https://www.jetbrains.com/resharper/

3. Optimize your build pipeline

When you’re developing your next very best app or game you are probably making a lot of builds per day. Each build can take up a few minutes or even an hour to make. This is bad especially because it’s impeding your work till the build is finished.

So let’s count the time you waste because of that process. Let’s say that your project is medium sized and need ~20 minutes to build on Android and ~1 hour to build on iOS. And you’re making 1 build per day at minimum. Now let’s sum up the time it takes to make those builds in one month (20 work days): Android builds – at least 6h 40m. iOS builds – at least 40h. This is more time than it took first spacecraft (Luna 1) to make flyby of the Moon in 1959! Which took only 36h! But how to save so much of your time? Use external tool to make those builds for you!

For a long time, the most popular one was Jenkins, which offers you a lot of flexibility. Also, it’s giving you basically unlimited possibility to configure your build pipeline to suit your needs, for example:

  1. Watch repository for new commits.
  2. Analyze code.
  3. Make a build.
  4. When finished, send build file to a FTP server.
  5. Send mail with a build report and a link to build file.

Of course there are a lot more options, and if you ever need more, then you can always add some. Oh, and I almost forgot! It’s available for free! So you just need to go to their website, download it and install it on your build machine 😉

More about Jenkins: https://jenkins.io

The other tool is provided by Unity itself and it’s called Unity Cloud Builds. It of course assures better integration with editor, where you can basically configure everything you need to start using it. Like Jenkins, it is also available for free, but with Unity subscription your builds will be higher in priority list and will be processed faster. Additionally, after each build Unity generates the link to your build to download or to share with your friends 😉

More about Unity Cloud Builds: https://unity3d.com/services/cloud-build

So what are differences between these two? Jenkins is open-sourced and has a huge library of plugins to install. You can for example integrate 3rd party APIs like Slack with it. Jenkins also allows you to configure it any way you like it and give you a possibility of setting up your own build pipeline. On the other hand, Unity Cloud is only focused around Unity and you can’t add anything to it. Of course you can configure Slack to get notifications from Cloud or use Webhooks that Unity provides, but that’s it. But the advantage is that it is straightforward, easy to configure and use.

Which one should you use? If you need something simple, then go with Unity Cloud Builds. If you need something more advanced, with a lot of configuration options, then go with Jenkins.

4. Store your data in convenient way

Many people put the data into objects on a scene or hardcode it somewhere else. With that approach it’s often hard to find where you have to make a change in order to achieve a desired result later in development…

But we’re here to present you two better ways to store data:

  1. Text Asset, which can be JSON, Excel file or any other text format. The problematic aspect of it is that in such file you can put only text, and you need to have a parser to read this file and get your data.
  2. The other and more convenient way is to create ScriptableObject. You can put there anything you like. Text, numbers, textures, material, models, etc. And most important thing is that you can use it like any other asset in your project and reading data from it is as easy as getting a variable.

Here is an example of ScriptableObject code:

And with that code you can easily create as many WeaponData objects as you want 😉

5. Auto references

Creating UI is not the most pleasant thing to do, mostly because you have many scripts, that need even more references, which you have to assign by hand. Wouldn’t it be great to have all of these references filled all by themselves?

Of course! Here is a sample implementation for that:

Here is class example of use of that implementation:

Here is how it looks in Unity:

These references were added automatically! 😉

Summary

So, here’re 5 tips that hopefully can help you exclude a chore part from the Unity development process and boost your productivity. I’ll be adding more tips like that in the next part, so stay tuned!

You can also subscribe to our newsletter, so you won’t miss our posts in the future!