Playing Sound on Marker Detected in XZIMG Augmented Vision

Prerequisite

I order to start this tutorial, you would need:

  1. You need to have finished the previous tutorial on Detecting Marker Detected and Lost
  2. You need a sound. You can find lots of it to download here

What type of sound format does Unity support?

It is best to go for mp3 sounds as sometimes in my experience the .wav have a tendency to not play properly.

Import Sound Into Unity

So you have downloaded the sound now lets import it into Unity. Drag and drop the sound into the Assets folder, in the Project window.

Using the downloaded sound

In the Hierarchy window, right click the Main Camera, under Audio, click Audio Source

An Audio Source will be created under the Main Camera. It will look something like this

Select the Audio Source, with the Audio Source selected, drag and drop the sound to the Audio Clip slot.

Next, uncheck Play On Awake.

Triggering the sound to play when marker is detected

Select Pivot1, look at the Inspector window, under Event Receiver, press the “+” at On Marker Found()

You will get something like this

Drag and Drop Audio Source to the Object Slot

Click the Function Dropdown, Go to Audio Source, and select Play()

Now lets Play it and test it out

The marker is detected and sound is now playing

Quick AR Creation Tip: Have a “toolbox folder”

If you are like me and have a lot of things to do with so little time ( that’s the way we like it!) having a “toolbox folder” saves you effort. In this post I will share what I have inside my toolbox folder.

I’m not saying this is the best way but I have a toolbox. This have almost everything I need, scripts I built from all these year so I just drag and drop my toolbox into Unity and I am ready to go!

I have one for each engine that I use. Here is what it looks like:

I have one toolbox for each engine. Ready to drag drop into Unity

A look into my Toolbox

Storage Template

When building anything in Unity, regardless what engine you are using it important to be organized. So my folder structure is something like this:

My folder structure

But I did not create it from scratch every time I am working on something. It is already arranged like so inside my toolbox. So, when I drag my toolbox in and all folders will be there ready to go.

The folders are already there ready to go

Ready Made Modular Scripts

Most of the things that we need to do in AR are quite repetitive in some sense or another. So, i build modular scripts that allows me to achieve an interaction quickly by drag drop a pre-made script and assigning the values in Unity.

Ready Made, modular scripts

Image Target Template Script

Image target template script is my default drag to a Vuforia Image Target. I rarely code interactions since the time I have this. It has all my basic functions like play animations, audio and event handling. Sometimes, this is all I need.

Image Target Template S

Audio Manager Prefab and Mixer

To avoid the repetitive task of managing and creating Audio Sources, All my Audio is managed by a pre-built AudioManager that has a group of AudioSource underneath it. The Audio Manager prefab is attached to the AR Camera so I won’t have volume problems. The AudioManager script has two functions:

  1. Control the play,pause etc.
  2. Allows me to play through an Audio Source based on ID. Hence, avoiding conflict that sometimes causes no sound to come out.

I usually need just 10 channels as most of the time, I don’t play more than 10 audio at the same time.

Audio Manager, It sits under the AR Camera

Conclusion

I am not actually preaching anything just sharing how I do things just so that it might be useful for everyone. Our workflows might not be the same so it is better to build your own toolset. I’m just showing this as an example.

What are your tips to make AR creation faster? Do comment below on what you think.

Arcolib (Edited 31st july 2019)

Edit : Today is a really sad day. I found out that Arcolib so far did not update their software yet to support the ARM64 architecture. That means we can no longer use Arcolib for Android apps and Apple apps soon. It will still work on Desktop soluions though. Play Store will start to enforce the removal of non ARM64 apps by August 1 this year. Exception is given for apps that is built using Unity 5.6.7 and elow until 2021. Lucky break for me coz my app are created using 5.6.7. Don’t judge me…, if something works i don’t touch it and I still keep the content updated.

Arcolib

First thing first: I know what you are thinking, he’s paid to blog this. Nope. This is just my view of Arcolib. One of my go-to solution for Simple to Intermediate AR applications.

Arcolib is found hiding among the waters of the Unity Assetstore. I happened to type Augmented Reality one day in the search box and there they are.

Cheap, simple, and good enough

I am a Vuforia user as well so i do have bias towards it there. But for simple, low cost projects I would go for Arcolib. It has seamless import into Unity, the event handling is okay once you get to know it, and there are examples to help along the way. Without being too babbly, i will try to tell what i really like about Arcolib

In-Unity Marker Generation

One of the things that draws me into Arcolib is the in-Unity marker generation. Image Targets can be created inside Unity, which is a godsend for people who like to work at cafes and random places where internet connectivity is a question mark. The ImageTarget generation is really fast and you can bulk generation markers from a selected folder. You can generate their version of barcode markers too. Handy if you are juggling a museum level Augmented Reality

QR Code as marker

One thing i like about Arcolib is the ability to use QRCode as markers as-is so no need to install 3rd party QR reader and stuff. This feature is especially useful when,  again you have so many items to show Augmented Reality of.

Some aspects that they could improve on

Number one in the fix it list is the demos. If you are reading this dear Arcolib devs, please craete a starter kit, name it starter kit, so that when i start i would already have an AR with Image markers, with animated model capability, and sound playing capability in one scene. So that i could just duplicate that particular marker, swap in my stuff and i’m ready to go. You are seriously missing out man. If there are template based development like that AR would be a lot easier for beginners and educators, the kind of people you should be going for as target market. They are teachers and beginners, many of them whom i taught say they do not have a lot of money but can afford your software.

Conclusion

If  you are developing simple AR and the project budget does not allow for you to use high-end AR SDK, this is a good Simple-Interdiate level solution if you just need Image based or QR based AR.

Note: You can find Arcolib from Unity Assets Store

Where to purchase assets for AR and VR

In order to build Augmented Reality, and Virtual Reality you will need resources. Usually, the best way to have an asset is to create one. But for some projects, a shortcut won’t hurt. Why build if you can buy the assets? Here are the main places that I shop around for my projects.

Unity Assets Store – The All In One Go To Marketplace

Since I use Vuforia + Unity combination a lot. This is where i go to shop for my assets. From low poly 3D models, to textures, designs, UI and other features. The best part is, if you buy it from here it will almost most of the time work for Unity, since it is developed for Unity.

Low-poly 3D Models

3D models are the core of our experiences most of the time. When I look for 3D models, I will habitually look for low-poly 3d models. These are the best because highly detailed, high poly models will be very heavy for our 3d engines to handle.

CGTrader Low Poly

CGTrader is my main source of low-poly 3d models outside of the Unity Assets Store. They provide various assets, animated and non-animated for you to use and they also provide conversion services if the asset is not available in your preferred format. Very helpful indeed. Some of them will require further processing, others are ready to import into our tools like Unity

Music, Sound Effects and Ambience

AudioJungle

You can find all sorts of sounds from the marketplace at AudioJungle. It comes with flexible licensing for different commercial applications.

Ready Made Codes and Templates

Yep you read that right sometimes its easier to have something to start with and just edit out some minor details instead. For this purpose, you need ready made codes and templates.

CodeCanyon

CodeCanyon has the templates and pre-made codes for you. Whether you need one to see how things work for reverse engineering or to make your work go faster try checking out this site to see if there are codes that you can purchase and use. Saves a lot of time.

Preparation tips for an Augmented Reality project

So you want to create an Augmented Reality (AR) project. Where do you start?. I will give you some hints and direction on how to safely and sanely get through the process of creating an Augmented Reality. Especially if you have no idea what you are doing.

First things first: Are you sure Augmented Reality is what you need to achieve your objective?

Some of my clients are actually not sure if Augmented Reality is the correct avenue to accomplish their goals. Most of the time they have goals but they do not know the medium that they needed. Some actually followed hype.

So have a look around in Youtube for videos of Augmented Reality and how people are using it and see if this is what you are looking for. There is nothing more disappointing than having gone through the project halfway and realizing this is not what you want.

Now, look for an example in Youtube or an app to serve as an example or a benchmark of the AR project that you aim to build

Having a video example will give you the understanding on what effect and capabilities you can achieve in AR. Usually, what you see is what mainly is possible to do in AR using the tools currently available. Sorry for “Popping your expectation bubble” but its good to understand beforehand what you can possibly do and what you cannot do. AR is amazing but it ain’t a wizard wand that can do everything you want. You will need to work around some limitations

If you are engaging an AR developer to develop your AR, having a video to show them give them a clear idea of what you are trying to accomplish and this will make the design and development processes a lot easier and smoother for both parties

If you are developing this on your own, look for an example or tutorial in Youtube that has a description of the tools they use or check out demo videos that the developers of the tools such as Vuforia has posted online to see what is possible to do when the tools are pushed to the limits. This way you can be realistic in what you are trying to achieve. Most of the time, their limit is your limit too. Try to push it, you can but take note that it might not end up like you expected it to be.

Okay, so where do we get the contents and resources from?

AR is the medium, the contents that AR carries usually are Animated 3D models, Static 3D models, Videos , Images , Audio etc. These are the resources you need to build an AR experience. So in this aspect you have a few options.

Note: Different tools uses different format for resources. Some requires 3d models in FBX formats, others can accept 3ds or obj. THey might require mp4 formats for videos, etc. If you are developing on your own check the tool’s documentation first for the required format. You might need to do some conversions if you do not have the correct format. So doing it right the first time saves time and sanity.

If you acquired the services of an AR developer, they usually have services and professionals that will take care of all this. Just make sure you are on the same page with them before giving them the go-ahead. Creation/acquisition/modification of these resources will cost money and requires time. This goes both ways for you and the developer. Content Development is a labour intensive process.

For self-developers, If you have the money you can buy these resources from websites such as CG Trader, iStockphotos or if you need a customized content, you should approach a professional. If you need 3D models, enlist the services of a 3D modeller, if you need animation, find a 3D animation professional. You might also need to enlist services from an Audio or Video professional depending on your needs.

If you self-develop and don’t have the money or are doing a non-profit work, you can search around for free 3D models, images, videos and audios. Work with your creativity to edit them on your own or enlist a help of a friend with such skills. Free things rarely comes in the format you need so some conversions might need to be done.

Start from an example/template AR if possible

You do not have to start from scratch everytime. Search around for tutorials that closely resembles what you are trying to do and start there. Some of them provides example files that you can edit and customize instead. You can also search around in Unity Assets Store, Code Canyon, and other websites for completed AR templates and start from there. Also look if you could utilize the samples provided by the tool developers. Vuforia have some strong samples that can save you hours of development. Time is money and sanity is important.