When Your Code Is On Fire

Disasters do happen when you are working on projects. I am reminded of a certain situation in which a junior programmer imported something into the core library and errors started popping up everywhere. Like “the whole house is on fire” situation. Now, I know about not touching production rules, backups, etc. There are systems put together in-place to stop this particular problem from happening. But this post is more of how to handle things when shit happens. This guide is mainly for Junior Programmers of Unity, but it may be of help for other software and languages as well.

Do Not Touch, Take A Break first

Hands off, stand up and go drink water. Take a break, take a deep breath, try to calm yourself as much as you can. When your code is on fire, you will be freaked out. But, trying to fix things when you are not having a rational mind is the worst thing that you can do to yourself, it will create more errors, which in turn might be harder to fix afterwards.

Accept The Situation

We screwed up, accept the situation. Things happen, we cannot change what has happen, but we can make up for our mistakes by fixing it. You might be getting an earful, but you need to make things better.

Analyzing the errors, and fixing it

You need to look at the errors that pops up. Here are some of the patterns you need to look at:

If the errors looks like it comes from the same method, variable or class reference:

This means, you have inadvertently overwritten a certain class or file. If the class/file belongs to you, you can fix this by finding out what changes have you made from the current version and the old version. But, given the fact that you are reading this guide I am assuming that its not you that developed that particular class/file. In that case, you would need to ask your co-worker that written the class to see if he has a backup. If he does not, he can still help you since he understands his code better than you. Just be sure to say sorry, thank you for the help, and buy them lunch or something.

If the errors looks like it comes from a particular library:

When this happens, chances are your library versions are mismatched, one of them is either older or newer. Find out what the old version number is. Download the old one, create a backup of the current code, replace the library with the old version. Sometimes, different versions of libraries have what we call breaking-changes. These are changes to the codes that makes our old implementation to no longer works. So, do not simply upgrade a library without glancing through the change notes.

If the errors looks like it comes from multiple libraries:

Sometimes this happens because you messed with or mismatched their dependencies. Chances are, there are libraries that uses the same dependency components from other libraries. Go through the codes that contains the errors and find out which dependency they share, and replace that dependency library with the correct version.

When all else fails

You tried fixing it, but it does not work, the errors does not make sense. Here is what you should do.

  1. Backup the code. I am literally asking you to have a backup of your error ridden project. Just in case you turned the fire into inferno, you can always go back to just fire.
  2. Isolate the parts that does not have errors, move them out of your burning project folder into another project folder. Save what you can from the burning wreckage. You do not have to start from scratch.
  3. Reimport the libraries, download from original/error free source.
  4. Bring one of the code files that have errors into your new project, see if it still burns in the new project. If it does, see what is wrong, and fix them first. Do not add more files until you fixed this one code file.
  5. Repeat step 4 until you have a working version again. It might take time, but this will allow you to focus on the problems one at a time.

Learning from disasters

Here are a few things that you can do to avoid such disasters:

  1. Backup!, Backup!, Backup! before doing any changes, especially to Production/Core.
  2. Do Not Touch Production or Core. Make a copy of it in your machine, and make changes in that instead. If it is okay, run it by your person in charge, he will move it to core safely.
  3. Always refer the person in charge before doing anything in Production / Core. They are the ones who are responsible for the whole codebase, do not bypass them, ever. They are the ones that will be either saving you from disaster or help you out of one.
  4. If you are not sure, ask and clarify.

Simpler Way To Play Animation for Vuforia (2021 Update)

Okay, you want to play an animation, then nooooooo………..the model has more than one animation, so what do you do? Do you go through the process and create transitions, add parameters and do all of that? No you don’t need to actually. This is a handy tool for doing things fast. Here is the download link, and also as usual the explanation part of it, coz what use is things that you don’t understand or learn from?

How to use

  1. Add the Animation Player script to your model, it will give you the names of the animation clip

2. Call PlayAnimation using Vuforia Default Trackable Event Handler or Button

3. Type in the name of the animation you want to play in the slot. Done! When your ImageTarget is detected, the animation will play.

The Editor Code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;


[CustomEditor(typeof(AnimationPlayer))]
public class AnimationPlayerEditor : Editor
{
    AnimationPlayer myTarget;
    UnityEditor.Animations.ChildAnimatorState[] states;

    public override void OnInspectorGUI()
    {
        // Assign the script to this inspector so that we can play with its properties
        myTarget = (AnimationPlayer)target;
        // create the menu and add items to it
        GenericMenu menu = new GenericMenu();
        
        GetAnimatorStates();

        GUILayout.Label("Animation State Name From Model:");

        foreach(UnityEditor.Animations.ChildAnimatorState b in states)
        {
          GUILayout.Label(b.state.name);
        }


    }

    void GetAnimatorStates()
    {
        // Get a reference to the Animator Controller:
        UnityEditor.Animations.AnimatorController animatorController = myTarget.GetTargetAnimator().runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

        // States on layer 0:
        UnityEditor.Animations.AnimatorStateMachine stateMachine = animatorController.layers[0].stateMachine;
        states = stateMachine.states;
        
    }



}

The Script (called AnimationPlayer)

using System.Collections;
using System.Collections.Generic;
using UnityEngine;


public class AnimationPlayer : MonoBehaviour
{
    Animator animator;
    // Start is called before the first frame update
    void Start()
    {
        animator = gameObject.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public Animator GetTargetAnimator()
    {
        if(animator == null)
        {
            animator = gameObject.GetComponent<Animator>();
            return animator;
        }
        else
        {
            return animator;
        }
        
    }

    public void PlayAnimation(string animationName)
    {
        if(animationName != "")
        {
            animator.StopPlayback();
            animator.Play(animationName);
        }

        
    }


}

The Explanation

This script has two parts. The first part is the editor extension. The reason we need the editor extension is to access the Animator’s Editor properties in order for us to extract the animation state names. This information is only available through UnityEditor.Animations.AnimatorController.

The second part is the script itself. We need this script to be two things, one is to become the interface that our editor script will rely on to get the reference to the Animator. The second function is for us to ask the animator to play our animation of choice.

From SkecthFab 3D Model to Unity + Vuforia

One of the complaints that I usually get from people that want to create contents but unable to do so is “I do not know how to create 3d models”.

Here is my proposed solution, you can use 3D Models from SketchFab for your Unity + Vuforia AR. In this video I have made, you will learn to import Animated SketchFab 3D models straight into Unity for use with your Vuforia AR. This tutorial will work with most models that has simple animations. If you want to import a model with multiple animations, you need a different method

Publishing Your Android App to Play Store – XZIMG Augmented Vision Tutorial 7 of 7

Final Roll-out

Click App releases

Under Production track, click Edit Release

Release to production window appears, scroll down and click Review

Confirm roll-out to production window appears. Click start roll-out to production

A confirmation window will appear, click Confirm

That’s it!, we are done! Click on your app menu, it will show that our app is now Pending Publication. Once it is approved, it will be on the Play Store

That is the end of our tutorial series on how to publish app to Play Store.

Thank you for following my tutorial everybody!

Publishing Your Android App to Play Store – XZIMG Augmented Vision Tutorial 6 of 7

Filling Up Store Listing Information

The Store Listing window appears. Firstly fill in your app’s short description and long description

Next, scroll down the page. Add the icon and screenshot

Scroll down a little more, and add the Feature Graphic

Scroll down a little more, under Categorisation, select your Application type and Category. The selection depends on whether you are building an AR App for education, games or etc. Select the apropriate settings for your app

Adding Tags to your app to make search easier

Click on Manage Tags

The Tags window will appear. Search for the appropriate tags suitable for your app. In this example, my AR is an Entertainment. Press Add to add tag

Confirmation window appears, press Add

Once you have added the relevant tag or tags, press the back arrow to go back to Store Listing

Scroll down all the way down to Contact details, fill in your email. On privacy policy, fill in the url to your privacy policy. Then, click Save Draft

We are done with this part. A green checkbox will appear beside Store Listing

A green checkbox will also appear beside App releases

In the next tutorial we will do our final push to the finish line

Publishing Your Android App to Play Store – XZIMG Augmented Vision Tutorial 3 of 7

Setting the Content Rating

Click Content Rating

The content rating window appears, click Continue

The content rating Questionaire appears. Firstly, lets fill in our email address and confirm it.

Next we will select our app category. Based on your app type, you will have to answer different set of questionaire. In this example, I will click Reference but yours maybe different.

You will be asked a lot of Yes and No questions, answer all of them and press Save Questionnaire

If there are no errors, the Calculate Rating button will become blue. Click Calculate Rating

Yeay! we now have generated the Content Ratings. Click Apply Rating

Our ratings are now applied. You will see a green checkmark at Content Rating. Next, we will set Pricing and Distribution

See you in the next tutorial

Publishing Your Android App to Play Store – XZIMG Augmented Vision Tutorial 1 of 7

Introduction

In the previous tutorial post, I have taught you how to publish a test app to Android. In this tutorial we will cover the topic that is a must for developer creating apps for Android, which is Publishing your Android App to Play Store.

  • This tutorial will be broken down to 7 parts. They are:
    • 1 : Getting your app ready and publishing it as Android App Bundle (.aab)
    • 2: Registering Google Play Console account and uploading the aab
    • 3: Setting the Content Rating
    • 4: Setting the Pricing and Distribution
    • 5: Setting App Content description
    • 6: Setting Store Listing
    • 7: Final Steps and Publish!

Prerequisite

You need a few things in order to put your app to the Play Store. If you are not a graphics guy, you would need to ask a friend with such knowledge to help with the graphics part.

  • A privacy policy for your app. You can get one from https://www.websitepolicies.com/. Websitepolicies.com will provide you a public link to your policy. This is what you will need later.
  • Graphics for Play Store
    • 2 Screenshot of your application (Don’t know how to screenshot? Learn Here)
      • JPEG or 24-bit PNG (no alpha)
      • Minimum dimension: 320 px
      • Maximum dimension: 3840 px
    • 1 High Resolution Icon for your apps
      • 32-bit PNG (with alpha)
      • Dimensions: 512 px by 512 px
      • Maximum file size: 1024 KB
    • 1 Feature Image
      • JPEG or 24-bit PNG (no alpha)
      • Dimensions: 1024px by 500px
  • Descriptions for your App
    • 1 Title (The name of your app)
    • 1 short description of your app (80 characters max)
    • 1 long description of your app
  • Note: All your descriptions must not contain:
    • User testimonials
    • Excessive details
      • OK : “This is an AR app on cats, for cat lovers”
      • Don’t: “this is an AR app on cats, brown cats, blue cats, silver cats, cat food , cat drinks, cats getting drunk in a bar and starting a fight, and many other cats”
    • Misleading references to other apps or products
    • Repetitive, excessive, irrelevant keywords, keyword spamming
  • Avoid including these:
    • Sexually suggestive images
    • Profanity and vulgarity
    • Graphic violence
    • Depictions of illegal drug use

Preparing for our App for deployment

Go to File > Build Settings > Player Settings

Change the App icon

Drag and drop your created app icon into Assets folder in Unity

Drag and Drop the icon to the Default Icon in the Project Settings

Creating a Keystore

Under Publishing Settings, Click Keystore Manager

In the Keystore Manager, Click the Keystore menu and select Create New > Anywhere

A save file window appears, save this keystore file somewhere safe.

Do not, i repeat do not lose this keystore file. Backup it multiple times! Without this keystore you will permanently unable to update your application. Both in Unity and in Play Store.

Next, we need to fill in the details as explained by the picture example below

Click Add Key

A keystore created confirmation window appears, click Yes

The key has now been set, under Project Key, click the Alias menu and select our newly created key value

Building our Google Play App Bundle

In the Build Settings window, select Build App Bundle (Google Play), then click Build

A save file window appears, select a folder to put the built file in. In my example, i put it in a new folder named AAB. Click Save

Once done, you will have an aab file in your folder

This is the end of Phase 1, in Phase 2, we will upload our app into the Play Store