Mega UI
Lifecycle
When your recipe runs, when your functions are read, and the window rules you inherit for free.
The order of things
| When | What happens |
|---|---|
Your Awake | You Register and Build. Nothing is drawn — there is no computer in the scene yet. |
| Player reaches a store | The desktop is built. Your icon appears and your window is drawn, hidden. |
| Player clicks your icon | Your Funcs are read, then OnOpened fires. |
| Player opens something else | Your window hides and OnClosed fires. |
| Player walks away | Same as above — minimized, not closed. |
Your recipe is kept, not run
Build takes a delegate because your Awake happens long before there is
anywhere to draw. Mega UI stores it and runs it when a window exists — and again whenever the
desktop is rebuilt, which happens more than once per session.
Any GameObject you kept a field for would be destroyed and recreated behind your back. Describing the screen instead of building it is what makes that a non-issue.
Numbers refresh themselves
Everything you passed as a Func is called again every time the window opens. For the
common case — a screen showing live values — you write nothing else.
// Read on every open. No timer, no event, no Refresh call.
r.Value(() => Warehouse.Count.ToString());Refresh is for shape, not for numbers
Call Refresh when the structure changed — a row that should not be
there any more, a section that only exists once something is unlocked.
private AppHandle _app;
private void OnFeatureUnlocked()
{
// The screen has a new section now, so it has to be rebuilt.
_app.Refresh();
}It is cheap and safe to call when the window is closed. It is not what you use to make a number update — that is already handled.
One window at a time
The game's computer does not stack windows: opening one closes the last. Your app is part of that rule, in all three directions:
| Player opens | What happens |
|---|---|
| Your app, with another mod's open | The other mod's window minimizes |
| Your app, with Shopping open | Shopping minimizes |
| Shopping, with your app open | Your app minimizes |
Before the rule existed, clicking Shopping with a mod window open opened Shopping behind it. The player clicked an icon and the screen did not change — which reads as a broken game, not a broken mod.
Walking away minimizes, it does not close
Leaving the computer hides every window and fires OnClosed. Coming back leaves the
desktop as it was. That is the game's own behaviour — ComputerUI calls
MinimizeAllTabs, not CloseTab — and your app inherits it rather than
inventing something different.
Exceptions cannot escape
Every callback you hand over — a Func, a click handler, OnOpened
— is wrapped. A throw is logged with your guid and swallowed.
This is load-bearing rather than polite: an exception reaching the game's EventSystem stops click processing for the entire scene. One mod's null reference would cost the player the mouse in the whole game.