Skip to content

KodeKit: colour tints without uGUI's tween garbage - #2779

Merged
sarbian merged 2 commits into
devfrom
ui/tint-no-garbage
Nov 20, 2026
Merged

sarbian merged 2 commits into
devfrom
ui/tint-no-garbage

Conversation

@sarbian

@sarbian sarbian commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

uGUI's ColorTint transition runs Graphic.CrossFadeColor on every state change of a Selectable. That builds a tween callback and starts a coroutine each time: about 1 KB of garbage per pointer event (enter, down, up, exit). Most KodeKit controls use it: segmented cells, stepper buttons, role buttons, list rows, title-bar icons, switches and checkboxes, and buttons in skins without hover sprites. A person moving the mouse makes a few such events a second, so it's a few KB a second, but it is the one place KodeKit still allocates per interaction.

KodeKit.InstantTint sets the Selectable's transition to None and paints the same ColorBlock colours into the target graphic's canvas renderer at once, as the transition does at the end of its fade:

  • states in Unity's order: disabled, pressed, selected, highlighted, normal;
  • pointer and selection events arrive at it as at the Selectable;
  • a change of interactable (code, or a CanvasGroup) is caught by one shared per-frame check over the live tints (a field read each);
  • a skin that swaps sprites instead turns it off (not destroyed: a restyle goes sprite-swap then colour tint within one frame, and a destroyed component lingers to the frame's end; that was a bug in the first commit, fixed in the second).

Visible change: the 50 ms colour fade on segmented and painted controls is gone; the colour changes at once.

Measured in KSP (MJTesting pad, release player, -c Release, 10 windows of 15 widgets each, every button and toggle hovered, pressed, released and left every frame; Spike 131 in MechJeb2_UI, jobs J21 on this branch and J22 on dev in the same session):

dev this branch
garbage per pointer event 1,041 B 6 B (noise)
frame with 1,360 pointer events 25.0 ms, 6 GCs in 8 s 17.1 ms, 0 GCs
idle frame, windows open 3.37 ms 3.27–3.34 ms (3.28 with every tint off)
skin switch (10 windows): restyle, garbage 5.4 ms, 36 KB 6.9 ms, 8 KB

The hover still shows: a hovered segment's canvas colour goes from alpha 0 to 0.10 at once (dev: 0.005 a frame later, mid-fade); kodekit_flat_hovered.jpg shows a hovered segment and a pressed stepper button.

Not changed: KodeUI's own defaults (UIScrollbar, UISlider keep uGUI's ColorTint; KodeUI is changed upstream), and a checkbox's tick still fades in with uGUI's CrossFadeAlpha when it toggles (a click, not a hover).

uGUI's ColorTint transition runs Graphic.CrossFadeColor on every state
change, which builds a tween callback and starts a coroutine: about 1 KB
of garbage per pointer event (enter, down, up, exit) on every
colour-tinted control. Most KodeKit controls are: segmented cells,
stepper buttons, role buttons, list rows, title-bar icons, toggles and
switches, and buttons in skins without hover sprites.

InstantTint sets the Selectable's transition to None and paints the same
ColorBlock colours into the target graphic's canvas renderer at once,
following Unity's state order (disabled, pressed, selected, highlighted,
normal). A change of interactable, by code or a CanvasGroup, is caught
by one shared per-frame check over the live tints (a field read each).
The 50 ms colour fade of segmented and painted controls is gone: the
colour changes at once. Sprite-swap skins hand the Selectable back to
its own transition.
A restyle switches a widget's look back and forth in one frame: the
skin's sprite-swap button look, then the widget's own colour tint.
Destroy is deferred to the frame's end, so Use found the dying component
and the control was left with no transition and no hover.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Build Artifact 🚀

MechJeb2-aaea957.zip (built from 7dac3f0)

@sarbian
sarbian merged commit f957bee into dev Nov 20, 2026
3 checks passed
@sarbian
sarbian deleted the ui/tint-no-garbage branch November 20, 2026 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant