Recently I was playing around with ProBuilder for Unity, watching video tutorials and reading the documentation. It all looked good until I tried to play around with the tool.
ProBuilder is truly a godsend tool for quick prototyping and level building. It extends Unity's editor with a 3D modelling environment that is very familiar to the full blown standalone applications (Maya, Blender, 3Ds Max, etc.). Using the tool becomes second nature and a must have for your team. However, one day when playing around with the UV editor, I decided to export the UV map so I can paint over it in Adobe Photoshop. And this is where I spent the next few days scratching my head.
The UV Template render tool is meant to export a png with the UV outlines as they are setup in Unity. However, to my surprise, the produced png is shifted a few pixels upwards. I played around with the settings and tried all the different combinations to no avail. I thought, maybe it is an issue with Unity 2019? But, after testing the same setup on Unity 2018, the issue still remained.
After a few hours of searching the internet for a solution, it seemed as if I am the only one encountering the issue. So I decided to dig into the ProBuilder code, debug the issue, and fix it once and for all.
After a few hours of digging into the massive code base, the issue seemed to be with the way Unity handles the positions in the OnGUI() function. Maybe it was changed from older versions of the editor? Not sure, but now I know where the issue originates from. Digging deeper into the script, I found a line of code that manually offsets the screenshot rectangle, supposedly to ensure that everything is grabbed in focus.... However, it seemed that the offset is only applied when the GUI window is in the docked mode? So I think to my self, "weird... I wonder what would happen if I switch the GUI window to floating instead?" and to my surprise, that fixed the issue!
Switching from docked mode to floating mode saved the day! Seriously? That's it? All these countless hours wasted just because the window was docked and not floating...
Of course, this could be an isolated issue that is only happening to me. But, if I am not the only one out there experiencing this issue, I hope this helps save you a few hours of head banging and scratching. Leave me a comment here so I know I am not the only person encountering such silly issue.