Category: Knowledge Nuggets

Getting started with the Magic Leap One

I have some great clients that enable me to play around with tons of interesting new stuff like the Magic Leap One. It’s great because you get to take a look at the latest and greatest but it can also suck pretty hard. It can suck because new stuff mostly does not come with instructions or those instructions were a “TBD” on the backlog. Yea yea, it seems like I am just whingeing about nothing but it’s easy to forget how frustrating a crash with no feedback is. This speaks volumes to the quality of SDKs being produced nowadays and of course, to that wonder that is the internet.

With moving some of our demos to the Magic Leap One, it was a mixed bag. Getting up and running was easy peasy! Beautifully documented with precise easy to find instructions. We had the device so no messing around with simulators.

A few things to note:

To get a certificate for deploying to a device, you will need a DUNS number (DUN & Bradstreet) If you have ever published stuff as a company on iOS, you should already have it. Good news, unlike the Apple App Store, approval was a couple of seconds. I have been told you can get a temporary certificate from Magic Leap but how and where I have no idea.The device takes a little bit of time to be found by the deploying computer. Before deploying your app, you will need to use the Magic Leap console, mldb, to check for devices. Command “mldb devices”…




Upgrading TextMesh Pro from an old Unity project

So If you are like me, you have a bazziloin projects you started, some you have finished and even some you have published. If you have made good money on your published projects, please tell me how! It’s almost the bane of a creator’s life to not get equally rewarded for their work… until you are dead I guess. Honestly, we live in an age that rewards creativity more than ever before (I think). Regardless of whether we made money or not, we still do it. We do it because it’s cool and we love it.

To that end, I have been bringing out some projects from the archives and upgrading them. These projects are mostly from the Unity 5.x time period (seems like forever ago!) The biggest issue seems to be migrating to the package manager included version of TextMesh Pro. You can spend weeks of your life rebuilding text prefabs. Thank goodness, the good folks at Unity have included a little tool to help. Im using Unity 2018.2.8f1 FYI. You can find this TextMesh Pro tool from Window -> TextMeshPro -> Project Files GUID Remapping Tool.

And this tool looks like (Yea I have Unity Pro! I do it just for the dark skin because I love my eyes!)

 

Now it’s tricky getting to…




Unity Debug Diaries: Camera Glitch in Unity VR

I have been doing a bunch of VR work lately and working with the Gear VR in particular. The Gear is actually a nice piece of kit and I can’t wait to get my hands on the Oculus Go coming out… soon. As of this post, the Gear VR has the largest market penetration of any VR headset. One bug that I encountered that was tricky to nail down, was an optical glitch when moving from one part of my app to the next. It looks like an uninitialized RenderTexture, different every time and with glitchy artifacts everywhere.

Turns out the culprit was render scale, now known as XRSettings.eyeTextureResolutionScale. ETRS (because I’m not typing it out every time) is great for getting “free” anti-aliasing on everything in your scene. It basically renders at whatever ETRS is set to (eg:1.0, 1.2) and then downscales to 1 for the final blit. Since its a downscale (bilinear I think), its best never to exceed 1.5 or things will start to look crunchy. If you just want to downscale, use XRSettings.renderViewportScale, which is way cheaper than ETRS. It can only accept values from 0 to 1, hence downscale. By doing this, you would trade visual fidelity for performance.

Back to the issue at hand, changing eyeTextureResolutionScale at runtime will cause a new texture set to be made for each camera, and those textures are uninitialized. That means that it has been allocated space in memory, but whatever was occupying that memory is still there. This creates the weird memory artifacts that you see for…




Unity Debug Diaries

Linear & Gamma Color Space in Unity & VR

Color space will come up sooner or later in your journey through game development. Unity has many great resources about this topic so it’s really futile for me to try and do it better. What I will do is give you the synopsis. Gamma is the old way and Linear is new. Use linear colorspace where ever you can. Its supported by most new GPUs and screens. On mobile, its supported on OpenGL ES 3+. The catch is, as of the time of this doc, mobile VR and especially, the GearVR. Turns out that there is a known issue, found on this Oculus thread, with the Qualcomm divers on Android. So Oculus, both in person and on forum encourage you to use Gamma for GearVR and Go.

That’s not all though. If you are like me and you are switching branches in GIT often, the Unity color space setting sometimes does not stick. This was especially evident in a recent project where we upgraded to 2017. In Unity 5, the color space setting had been changed a couple of times but what we were seeing as linear was not actually correct. When we did the upgrade, the color space was still strange until we toggled the setting. So if your color looks weird, toggle that setting first before you do a major overhaul.




Unity3D Pro Tip

Unity Pro Tip: Gradient Property Color Stepping

An example of the fixed color step of the gradient property.

Unity updates fast and furiously and one thing you might have missed is the Gradient property update. With them already working on 2017.2, they have been busting it out! With this breakneck pace, you will undoubtedly miss some the coolness. Now, commercially, I am still on 5.6, but that just got released this year so I don’t feel too bad. Plus, there are a bunch of issues I encountered migrating to 2017 with Text Mesh Pro. So, if you are going to start a new project, go for it but I warn you, migrating existing projects will be a pain.

One of the little things you can find in 5.6 and above that is super useful is the upgrades to the Gradient property. Most commonly found in the Particle System component, the Gradient property can handle the linear interpolation of up to 8 colors. It also handles the interpolation of alpha separately with the same 8 key limit but on a separate track, meaning it’s not tied to the color keys. If you have not already used it for something else, consider it! As a programmer, you can expose color transitions for artists and game designers by just adding the field! It uses the same evaluation method as the curves property. Just call “myGradient.Evaluate(0.5f);”, 0,5f being the time or ratio. It serializes to boot, so great for JSON but it does create more data than you would think.




Unite 2014 Presentation: BUILDING A SOLID FOUNDATION

Video recording of my session

Presentation slides




Locking layers in the Unity scene

Every now and then, while working Unity, I find that they changed something. It’s Like Déjà vu in the Matrix, but in a good way. This time I found that you can lock assets in place in the scene view. Its really weird because I was just lamenting about this, and “poof”, there is it! Its incredibly useful when you are laying out a 2D scene or UI against a comp where you are trying to match the source image your artist gave you. The problem was that, while placing or moving items, I would continuously selecting the layout image and then moving that. OMG, the pain! Now, I just make a layer in my project called “layout”, place my source image on that and then lock it. I make my source image a Unity sprite because A) its super easy to drag and drop into the scene and B) the layer locking only works with Unity native objects… not with 2D Tool Kit sprites. So Here is how you do it

Nift Unity layer pop-up for locking and hiding layers

Click the “Layers” drop-down in your scene view
Click the little lock next to the layer
Enjoy (preferably with a cup of coffee)




Connecting the Unity Profiler to your iOS Device

While doing some contract work recently I found that the Unity Profiler no longer reports accurate texture memory figures for mobile while you are in editor. Maybe it never did but I swear it did an some point. Rest assured, all the texture compression settings are still fine, you just have to test on device now. I had never done this with the latest release of Unity and remembered the days where I wished I could. So I gave it a bash and it is dope! Here are the steps you follow:

Make sure your mobile device is on the wifi network. The profiler uses a network connection to send data back to Unity.
Make sure you have “Development Build” and “Auto Connect Profiler” check to on in the build settings (handy shortcut for the build menu, Command + Shift + B)

Build for XCode. Make sure you are using a profile that allows you to be running the XCode debugger, so not an enterprise profile.
When the game launches, grab the IP address that appears in the XCode debug console. It will have a port number so make sure to get that as well.

In Unity, in the profiler, click on the “Active Profiler” button in the bar at the top. Sometimes it picks it up automatically, but if not, dump in…




Resizing Textures In Unity

It sounds silly but its true! Unity does not have any methods for resizing textures. Experienced readers might object, “what about Texture2D.Resize?” you say. Well, turns out that Texture2D.Resize only resizes the texture container, like trimming an array. Unlike trimming an array, Texture2D.Resize also sets the pixels to undefined. So really, all its doing is changing the amount of memory allocated. Thats all a bit disappointing, especially when you might be wanting to build a multi resolution pipeline for mobile. The weird thing is that Unity does this already when generating mip maps. So, lets roll up the old sleeves and figure this out.

We can get pixel data from texture, check! We can alter the pixel data, check! We can put pixel data into a texture, check! So whats left? The algorithm to resample pixel data. Resample is really the operative word because we are going to sample the source texture from the destination texture, pixel by pixel. This is exactly how pixel shaders work. So, We have our source texture at 1024×1024 and a destination texture at 512×512. What we are going to do is iterate through that 512×512 grid, find the corresponding color from the source texture and fill out destination pixel. Now we get to words you might have heard but never have known what they meant. Bilinear sampling is most common in games and gives a good understanding of how to sample but we are going to start with a technique called Nearest Neighbor. Resampling is mapping one set of coordinates onto another. So…




Unity & MonoDevelop 4 Woes

Unity usually always brings it to the table with their updates but sometimes they miss a few things. The MonoDevelop 4 is shiny but has one serious problem with the basics, at least on OSX. This is code folding! At first, code folding looks great. I do like the ability to fold “if” statements, but after I update something, all hell breaks loose and I can’t fold anything anymore. My workflow relies on folding to help me navigate code (as I think it is so with a lot of other devs). So here are some steps to get back to the old version of Mono. I am on OSX Mavericks, on a mac book pro BTW. I am not sure if yall PC people have the same issue, but then you are probably using VS.

Dual Install Unity
Most people don’t know, but you can have multiple versions of unity on your machine. First, uninstall all your Unity instances. Next, do an install of Unity 4.2.2 (anything that is before 4.3). Once you have done this, rename your unity folder. I just rename it to “Unity 4.2.2”. Now install teh latest version of unity. So now, you have both versions of unity installed on your machine. The folders are “Unity” for the current and “Unity 4.2.2” for 4.2. Make sure update your shortcuts in your dock.
Link To The Old Mono
In the current install of Unity, open the Unity preferences and go to External Tools (Unity->Preferences->External Tools ). There, select “External Script Editor” and “Browse…” to open…