2024 Guide to UIToolkit for Unity games (part 2)

(if you missed it, read Part 1: "Understanding UI Toolkit" first) Part 2: Getting the best out of UI Toolkit and Flexbox Benefits to UI Toolkit Downsides to UI Toolkit Best of both worlds: Flexbox with Unity UI Benefits to Unity UI / FlexBuilder Downsides to Unity UI / FlexBuilder Building A User Interface Using ... Read more

2024 Guide to UIToolkit for Unity games

Part 1: Understanding Unity UI Toolkit Introduction to Unity UI Toolkit Unity UI Toolkit is a robust and versatile user interface framework designed for building high-performance, scalable interfaces within Unity. This toolkit allows developers to create UI elements that are easily adaptable to various screen sizes and resolutions, using Flexbox (part of the CSS standard ... Read more

Feature: force a relayout/update from script

FlexBuilder is deeply integrated with core Unity and will automatically relayout whenever it needs to. In 95% of cases you won't need to think about this - FlexBuilder and Unity will handle it. But there are still a few cases where the changes can't be detected automatically (typically because Unity is missing the required callbacks) ... Read more

Categories FAQ

Best practices for high performance when using FlexBuilder via script

The main thing to bear in mind when aiming for performance is that FlexBuilder will always default to "doing the right thing" -- which may be a lot slower than necessary. For instance: if you write a script that adds 100 FlexItems to a FlexContainer, FlexBuilder will automatically re-run the layout algorithm ... 100 times. ... Read more

Categories FAQ

How to draw an array of items in UIToolkit in UnityEditor

After a few years of working with UIToolkit, and continually deploying it in apps and trialling solutions from the community, I eventually arrived at this "simple" code example that appears to work in all versions of Unity from 2019 through 2021+. I'm using this in production, will update this post if I find new problems ... Read more

Problem: CACHE_STRATEGY is too agressive

When building flexible UI in Unity3D you may sometimes see this message on the Unity console: FlexBuilder: Your CACHE_STRATEGY is too aggressive! - Cache contained an object Unity had already destroyed TL;DR: quickest solution If you just want to make the warning go away then you can safely comment-out the line of code that produces ... Read more

Categories FAQ