Mirrored Animation

The character in WOTT is a humanoid, which provides a number of advantages. One is that animations don’t have to share the same rig as the final character. That gives me the flexibility to make changes to the rig without having to remake previous animations, and also provides the ability to create animations using a variety of software packages if needed.

Another big advantage is that humanoid animations can be mirrored in Unity with a single checkbox. This halves the animation workload for unilateral, or Left/Right exercises which is important because there will eventually be thousands of exercise animations in WOTT.

With so many animations, it’s important that the users only download the animations they need for the routines they use – there’s no point downloading or storing animations they don’t use. To accomplish this I needed a way to create animation graphs on the fly which can’t be done with Unity’s Mecanim animation system. The only way to do this with the necessary flexibility is to use AnimationPlayables. So I needed to create my own animation system.

I originally had a month scheduled to create the animation system in WOTT, after which I had a month scheduled to create the database and backend. After a month I didn’t get everything done that I had planned, but I was happy enough with where the animation system was.

The fundamental elements of WOTT’s animation system are the ability to create downloadable animations, and then plug them into an animation graph when needed. Completing the animation system was always a long term project, but for now I just needed those fundamentals working so I could create exercise animations while I worked on the backend. Then, in a month, once the backend was done I could continue working on the animation system.

There were just two problems with that plan. The first was finding the time to create animations while trying to get the backend working as quickly as possible – two competing goals that the backend usually won. The second problem kind of snuck up on me around the time I felt like the backend was getting close to being complete, 5 months after starting work on it.

Continue reading “Mirrored Animation”

Mirrored Animation

Visual HTML Editor for Unity Mobile

WOTT’s routine descriptions are a mix of standard rich text tags for styling, TextMesh Pro <link> tags for links, and my own <img> tags for images.

When I show the description, I parse it, separating the images from the text, and then create blocks of text, images and buttons (for images with links). I also complicate things by adding a <color> tag to links so they stand out.

The first version of the editor, which I knew was terrible, was just a big input box, which opened the full description. It allowed simple descriptions to be written, but relied on the user understanding tags for any styling. Because you can’t select in an input box, the only way I could add styling, links or images was to just add them to the end of the string, and let the user move them if they wanted.

Continue reading “Visual HTML Editor for Unity Mobile”
Visual HTML Editor for Unity Mobile

Optimizing Unity UI

Unity recently posted a guide to optimizing the Unity UI:

Optimizing Unity UI

https://unity3d.com/learn/tutorials/topics/best-practices/guide-optimizing-unity-ui

I was very eager to read it, because up until now there hasn’t been much information about those topics. I look forward to more of this kind of information being included in the manual, but until then it’s great that this has been made available.

It came at a really opportune time, as I was starting to optimize my UI, but I had so many questions that weren’t answered in the manual or the forums. Luckily some of those questions, and probably the most important ones, were answered in those posts. Yay!

One of the things I’ve struggled with is keeping draw calls low. I have a complex UI with many moving parts, and at times it’s had a ridiculous number of draw calls. As I’m still adding functionality, I haven’t properly begun the process of optimization yet. That will come as I replace the placeholder graphics with final graphics. But there are many things I could have done to make the UI more efficient from the beginning.

If you’re just starting out, some of the information in Unity’s guide may go over your head. But there are some real gems in there which can help to make UI creation much more efficient, and definitely increase performance. Here are some of the things I learned:

Continue reading “Optimizing Unity UI”

Optimizing Unity UI

Most Accurate Timer in Unity

In our current project, a large part of the functionality relies on a timer. When it boils down to it, the accuracy of the timer isn’t hugely important so long as it’s consistent, but I figured the most accurate method is likely to also be the most consistent.

There are three basic ways to implement a timer in Unity:

  1. +=deltaTime in Update()
  2. InvokeRepeating
  3. Coroutine

I’ve seen quite a bit of discussion about these different methods, but there appears to be some disagreement about what’s best and why. None of the discussions I’ve found have included the results of any tests to compare them or demonstrate accuracy or efficiency.

I’ve been avoiding Update() where practical – using Coroutines or Invoke instead if something doesn’t need to be checked or done for every frame of an object’s life. But with two other methods available, I didn’t know whether a Coroutine with WaitForSeconds or an Invoke is a better way to create a simple delay. It doesn’t really matter too much for one off events, but for repeating events, or if you have lots of them, delays can add up fairly quickly.

Continue reading “Most Accurate Timer in Unity”

Most Accurate Timer in Unity

Get the Right Component!

I’ve been using Unity for a while, but I’ve only been coding (for realz) for about a year. I’m currently refactoring some of the code I wrote a year ago, and seeing lots of things I can do better.

One thing I’m seeing way too much of is this:

I’m assigning a GameObject in the inspector, and then getting the Image component in Start().

What’s wrong with this?

In many cases I don’t need the GameObject beyond the Start() method, so having it hanging around is pretty much pointless, and getting all those components at the start (or any other time) causes an unnecessary delay.

Continue reading “Get the Right Component!”

Get the Right Component!

Unity uGui Button Long Press

ButtonLongPress

I’ve been spending a fair bit of time with Unity’s UGUI for my latest project. Having wrestled with it for a while, in some ways I wish I’d stuck with NGUI, but I’ve learned a lot along the way so it’s not all bad.

In my UI I have some buttons which open sub menus, but I wanted to be able to rename the menu item as well. Since the target is mobile, right click is out. I thought a long press would be an intuitive way for users to change the name, so I had a quick look to see if anyone had already done this.

I came across this Unity forum post which has a script/component that works quite nicely.

The thing is, I’ve been avoiding including any Update() methods in my UI to keep it as speedy as possible, so I rewrote that long press script to avoid Update() and it’s turned out to be a fair bit quicker as well:

Continue reading “Unity uGui Button Long Press”

Unity uGui Button Long Press