Posts

Showing posts from September, 2021

CSS-like layout for Unity UI - Lessions from web development workflow

Image
Unity UI really is a pain, especially for mobile - the environment which the engine is really used widely in. You put everything into place for one screen aspect ratio, and then you switch to another screen aspect ratio and suddenly, the whole thing breaks. Left: Standard 9:16 layout. Middle: Same scene, in iPad Pro 11 (highest aspect ratio scenario). Right: Same scene, in Xperia 1 III (lowest aspect ratio scenario). This is a longstanding issue with Unity UI that has yet to be comprehensively covered by any guide I can find. Unity developers are just sort of... expected to figure this out. A major part of this issue is that Unity Editor's interface just naturally guides you toward using pixel count to layout UI elements, when this is absolutely the wrong way to handle multiple resolutions. Pixel numbers are absolute in Unity UI. Even with a Canvas Scaler set to a fixed reference resolution, it still cannot account for multip...

A better way to get letterboxing in Unity

Image
Alternative title: A critique of the existing Unity letterboxing solutions and how to improve them In a video titled " Handling different aspect ratios in your Unity 2D games ", Rabidgremlin pointed out a real issue with aspect ratio scaling in Unity: Different section of your game world is cut off from view when you switch aspect ratio due to Unity trying to preserve the vertical FOV of a camera at every moment. However, the solutions he chose have... problems. You see, the solution that Rabidgremlin chose for this issue was an asset on the Unity Asset Store called " Auto Letterbox ". The way this asset implements letterboxing is:  - At runtime, in a Start method, find all cameras in a scene using a FindObjectsOfType<Camera> call, save them to a list, modify each of their viewport rect to limit what they can display to fit the target aspect ratio. - Instantiate a new camera, set its background color to the color you would choose for your letterbox, set its...

Unity: The little default setting that kills mobile performance I wished I knew sooner (TLDR: It's Vulkan)

Image
Hey all! I just found out about something that quite possibly gave me the biggest "BRUH" moment in my career as a Unity developer. I just want to share this experience of discovery with you all and who knows? Maybe this is new to you too (it probably isn't). So let's talk about an innocent little default setting of any newly-created mobile project. Here it is:   This doesn't look wrong on its face, right? Vulkan is a low-level graphics API that usually sees better graphical performance and power efficiency in desktop and console games. Surely this is the better choice for graphics API. Or so I thought, so did my colleague think. The thought of Vulkan being the culprit of our game constantly dipping below 50fps even with a very simple scene never crossed our mind. What my colleague thought was going on was a combination of Linear color space, post-processing effects and HDR causing this performance impact. He ticked on Auto Graphics API, which doesn...