Unity Versions Tried: 2020.1/2020.2
Mobile Device: Samsung Galaxy M20 running Android 10.0
Computer OS: Windows 10
USB Connection: Type C
Ever since Unity 2020.1, our project can’t consistently connect builds to the profiler. Unity 2019 was okay-ish (sorta) but Unity’s profiler connections overall have never been rock solid in any version compared to android logcat.
This is especially sad considering one of the changes in 2020.1 that got me excited.
I have been pulling my hair out over trying to get a profiler reading and data dumping via profiler API is NOT an option because our game’s flow is dynamic and I want to test it in realtime while playing through and get profiling data directly on the editor. The build turnaround time is already bad enough, having to add an extra layer of “dump data → copy → open raw file in the profiler” is going to completely kill the dev cycle with far too much turnaround and not enough work done to solve real problems.
We moved to 2020.2 specifically for the new profiler API that will let us show stats on builds directly but that will take a bit more time to create the HUD. I’d appreciate it if someone from Unity could direct me to the docs for this new 2020.2 profiler API because I’m having trouble finding it. (EDIT: Nevermind, found it — Unity - Manual: Rendering Profiler module )
We were also hoping that maybe the profiler connection issues will be resolved. Sadly it’s worse than ever for us.
I was able to get it to work once in a blue moon using the same steps provided below and I can’t recall which step it was but it is far less than consistent. It MIGHT work once every 3 days!!! And after working once if I need to build again, it stops working. This is just unacceptable for development. Even trying the same exact steps that makes it work all of a sudden won’t make it work again. It is completely random. I wouldn’t call this “Stable” and it shouldn’t be so hard just to profile an android build.
Firstly, here is what I’ve always done to connect the profiler:
-
Set the “Run Device” from build settings to my USB connected Android phone. Hit “Build And Run” with “Development Build” and “Autoconnect Profiler” checked on.
-
Launch the app and switch to “AndroidPlayer” on Profiler dropdown:
Unfortunately, “Build And Run” has a problem that is apparently “By Design”…
This is the resolution note on the issue. Basically using just “Build” and “Build & Run” differs because of BuildOptions.StrictMode preventing “Build & Run” from producing the APK if any errors or exceptions occur. However “Build” works just fine and we do not have time to go hunting down every little issue on builds as long as it succeeds.
This “By Design” issue persists on to 2020.2 so “Build & Run” is out of the picture, I have to use regular “Build”. Fine.
Now on to the main event.
If I could “Build” the android APK, launch it on phone and get the editor to magically find it, things would be okay enough to at least keep developing. But basically it’s next to impossible and works in extremely rare cases as mentioned above!
1. Upon reading through the docs on android profiling:
I came across “Android Remote Profiling”
I disabled mobile data on android device, connected PC + Android to same wifi. Disabled the network adapter for ethernet on PC to be safe. Install APK that was created using just “Build” on android and launch the profiler and try to connect using ADB/IP. Nothing worked. I checked the phone IP (192.0.168.100) which is always the same since no other devices connect to my home wifi (working remotely for our company).
It. Did. Not. Work.
Nothing, tried changing the sequence of the above to make sure I was doing it all the right way, it would never connect.
2. Next I tried ADB profiling. I even configured the adb tunnel manually on CMD using the following command:
adb forward tcp:34999 localabstract:Unity-{insert bundle identifier here}
I inserted our app’s bundle identifier in braces {} and the command worked fine. But even while being connected to USB there was absolutely no sign of profiling data.
Please note the following:
-USB Debugging is turned on
-Android Version 10.0
-Android drivers are installed, I can look at the device storage just fine
-The Build window can see the device as the “Run Device” just fine
3. Assuming it’s a firewall issue I tried the following as suggested by the docs:
Firewall:
I added two new Outbound Rules to Windows Defender firewall to make sure it wasn’t blocking anything. One was for TCP ports 54998-55511 and another was for the Unity 2020.2 application in general for any protocol and any remote port. I tried the first one alone and then added the second one to make sure I covered everything. Still didn’t work.
I also use Avira free edition but it’s for viruses only.
I also always allow the firewall popups that come up when installing Unity.
On profiler, sometimes when switching to “AndroidPlayer(ADB@127.0.0.1…)” I get:
“Connection is no longer valid. Calling auto disconnect.”
And it switches back to Playmode/Editor
I try using the IP address to connect and get the following:
“Failed to connect to player IP: 192.168.0.100:55000-55511,35000,4600,4600. Player did not respond”
I manually enter “192.168.0.100”. It won’t work. I also tried “192.168.0.100:5555” because 5555 is the port android logcat uses, nothing.
4. Android Logcat
I am mentioning android logcat here because it has a sort of SUPER connector where the moment I launch the window it automatically shows Connected in green without having to do a thing, similar to how the Build Settings is able to find the “Run Device” every single time on refresh. Both of these parts of the engine can detect the android device 100% rock solid without failure every single time as long as its connected to the USB.
So WHY can’t any of the profiler tools :
Why can’t Unity borrow a page from the android logcat package and implement something similar for the rest of the profiler suite (Profiler, Console, Frame Debugger, Memory Profiler) so that connections are rock solid every time like android logcat??? Even logcat is able to show realtime graph of heap size/heap alloc in addition to console entries. Disconnect/Reconnect is super straight forward at the press of a button.
And by clicking “Other connection options” on the device selection dropdown on logcat, I can see the IP of the phone + port that it is using in addition to android version, abi, sdk, id, phone model number, EVERYTHING basically. If android logcat is discovering the device so splendidly and is able to gather so much info + show realtime data from the phone + connect with such ease, why on earth is there so much connection difficulty with the more important profiling tools?
It is like instant! I disconnect USB and it shows Disconnected in red, I reconnect USB and don’t have to do anything, it just finds it and starts showing data!
If the rest of the tools could connect as easily as android logcat, gathering performance data would be super easy and development headache would decrease by a huge margin!
In a perfect world we’d have android logcat level connection to profiler + bluestacks level android device emulation directly in the engine so there would be less “device-only” bugs that constantly require us to make builds and test to see what is happening on device and with profiler tool connections being this poor, we are left completely blind making mobile development just completely SUCK
Please if someone from Unity could help out we’d highly appreciate it! Also to know if you guys are working on stabilizing these connections the right way like logcat. Without profiling we should might as well just give up mobile development!
We BADLY need android logcat-like connection in the profilers! Please guys lets make this happen!
At the very least please tell me what else we can try or if amongst the above there is one sure fire way to do it every time with an extra step for stability not mentioned in docs???