Tag: Unity

Unity Debug Diaries

Performance Myth Busters: Variable Allocation

In Unity Performance Myth Busters I take an assumption and check if it’s still valid or just programming superstition. There is nothing like proof to end an argument or inform a decision. Plus, there is nothing like being humbled by a junior dev because you did not do your homework! Today, I want to chat about local variable usage in an update loop. So, you have all seen a loop like this:

private void Update(){
Vector3 eularRotation = assetToRotate.localEulerAngles;
eularRotation.y += Time.smoothDeltaTime * 10f;
assetToRotate.localEulerAngles = eularRotation;
}

So I created a project to test my theories. I am running on a MacBook Pro, Unity 2017.3.1f1, compiling for Mac standalone. At first, I run it in the editor with the profiler and we are getting the typical GC sawtooth curves. But as we know, profiling in the editor is a lie. Profiling a build, GC is a flat line! No change what so ever. That’s great news but is it only that the change is so tiny, we cant notice? Possible.

Next, I ran 64 instances of my test… and that was a flat line too. Before I bust this myth though, I want to make super sure so we are going to try 100k instances… because I can… and for science. Yea, that was a little heavy-handed. Let’s try 20k.

So after 20k instances of the above code, I can safely say local variable assignments does not generate garbage. Solid like a rock and myth busssssted!

All my Performance…




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.




Unity Debug Diaries

Unity Debug Diaries: Mip Map Memory Reduction

First off, I must apologize for the weird tense swapping that happens in these articles. I write stuff as it happens and do not want to do too much editing lest these become too tedious to write and then I just stop completely. So if you can deal, I will continue to write 🙂

Today, I am attacking using Mip Maps on UI for multi-resolution rendering. Enabling Mip Maps and managing which of the maps are loaded into memory is the easiest way to handle texture memory on lower end devices. Now, I believed this but did not see the reduction in the profiler on device. So then I figured it was a fallacy because the data suggested otherwise. I then switched to TK2D to handle a lot of my multi sized sprites but the lack of clarity on the issue always bugged me. So now, I want to find out for sure. I cant get a straight answer out of anyone so its time to set up some tests.

First, I am going to make a separate project in iOS to have a clean environment and have nothing muddy my results. I am choosing iOS because its got its own set of profiling tools that will help me isolate if the Unity Profiler is telling porky pies (lies).
Results: Lies lies lies! So profiling in iOS showed a radical drop in memory based on the appropriate quality settings. I have four 2048×2048 at 32 bit. The results in the profiler are:

Full resolution: 107.66mb
Half resolution: 43.68mb
Quater resolution: 27.69mb

These results…




Unity Debug Diaries

Unity Debug Diaries: Radically long load time on Kindle Fire HD

One of the most useful things in day to day game development is to know about those weird gotchas that you find in any complex tech. On top of that, you need to remember said gotchas the next time you encounter them. When developing cross platform games at a fast pace, I have solved problems and completely forgotten the solve the next time I bump into it six months later. Debug Diaries is my first attempt at trying to curb this. When I am faced with a weird problem, I am going to try to fix the problem while writing about it so that I can remember and hopefully, help you too. Here goes…

On doing the Amazon port of our soon to be released game, Thunder Jack’s Log Runner, I found that after adding the plugins to the port, the game too about 5 to 10 mins to load. I have seen this before when loading a lot of textures from resources but can be sure. The last thing I added before the problem was AdColony, which could have pushed me over the memory threshold. Time to pull it out and add some debug logs.

The first thing I did was to switch from my amazon branch to my google play branch to see if the problem was inherent or platform specific. For those who don’t know, most Android builds will work on Amazon devices because they are Android. You just have to watch out for the platform specific plugins.
Result: Same thing. So now, I am…




Kindle Fire HDX and Unity

Unity and the Kindle Fire HDX… a Christmas story!

As most of you know, I have been working on my wife’s game, Notespace, for the last year. It has been an epic adventure filled with joy and peril but treacherous waters of publishing on Android. You can avoid a lot of the problems by publishing multiple builds per texture compression but every now and then you get those sharp rocks that come out of no where. And that, for me, was the mysterious crashing on Kindle Fire HDX devices.

Now before I move on, for those that don’t already know, Android devices use an array of GPU’s where as iOS devices only use one (Power VR). This generally does not affect you in anyway except when it comes to texture compression that has alpha. Unity’s default Android compression setting is ETC 1/ RGBA16. What that means is that it will compress power of 2 textures with no alpha as ETC 1 (an older OpenGL format) and will set compressed textures with alpha to RGBA 16. On average, RGBA16 will be at least double the size as your compressed texture so it has the ability of sending your GPU memory usage over the edge. That being said, I have not actually seen that happen on a device but that kinda means nothing on Android with a gazillion devices on the market. Whats more important is that 16 bit textures can look really bad, especially if you have a lot of gradient work. So there is 2 ways around it. 1) Build a custom shader for your compressed images with alpha…




Unite 2014 Presentation: BUILDING A SOLID FOUNDATION

Video recording of my session

Presentation slides




CMR #13 Playnomics

Collective Mass Radio #13: Playnomics

As always, check out the rest of the blog as well as the other Collective Mass Radio podcasts on the site. Big thank you to Chethan, the CEO of Playnomics, for taking the time to chat and to his team for all the scheduling and internal chats. For more info on the company and the big man himself, check out this article on Venture Beat. Follow Playnomics at @Playnomics and check them out on the web at http://www.playnomics.com. If you are interested, apply for the closed beta of the new product. I have and what I have seen so far is great. The guys are really paying attention to the important details. Now, go build the best game ever!

 




Collective Mass Radio #10

As always, check out the rest of the blog as well as the other Collective Mass Radio podcasts on the site. You can follow Adam at @AdamTuliper and check out the great Microsoft offerings for Unity at http://unity3d.com/pages/windows/. Be sure to check out their events section for hands on Unity workshops near you.