Tag: Profiling

Unity Myth Busters

Unity Myth Buster: GameObject.Transform VS Cached Transform

Caching the transform was one for the first Unity optimizations I ever learned. It was drilled into me like scripture. But things change all the time, and Unity is the fastest evolving software platform I have ever used. Kudos to you Unity! Now I started using Unity back at the end of the 2.x cycle and we have come along way. IL2CPP is freaking amazing. The more profiling I have been doing, the more blown away I am by it. You will clearly see why by the results.

Enough blather, what we are going to be doing here is evaluating our assumption that caching the transform object is faster than referencing it from script or a game object. We are going to be taking our readings from device to be as accurate as possible. In this case, a Samsung Galaxy S8 (Android). I will be providing a link to the evaluation project so please report back with numbers from other platforms if you get different results. Test results from the editor are unreliable and don’t allow you to make use of IL2CPP optimizations.

The Setup

I wanted to check both performance and memory allocation here so I had to do some shenanigans. The most accurate way to get memory allocation readings that I know of is the Unity Profiler. To use that effectively I needed to separate the tests so that I could fire them manually after I had connected the profiler. So I made UI but the Unity canvas and event system creates its own garbage, especially…




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…




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…